sliccy 6.99.7 → 6.99.8
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/ui/.vite/manifest.json +389 -614
- package/dist/ui/assets/__vite-browser-external-CyeY5rFA.js +1 -0
- package/dist/ui/assets/{account-store-y43KgcoW.js → account-store-BHr78r-q.js} +3 -3
- package/dist/ui/assets/{account-store-llwJaGRg.js → account-store-DhN2-vXh.js} +5 -5
- package/dist/ui/assets/adobe-BgNEArvI.js +2 -0
- package/dist/ui/assets/{adobe-C30ITWqR.js → adobe-C-61Gw8p.js} +1 -1
- package/dist/ui/assets/agent-panels-DwH4FR7k.js +1 -0
- package/dist/ui/assets/{anthropic-messages-DbPJ2ji9.js → anthropic-messages-B7p0objs.js} +1 -1
- package/dist/ui/assets/{anthropic-messages-CpSojOI8.js → anthropic-messages-JQYJ-RUq.js} +1 -1
- package/dist/ui/assets/{apply-layout-CyFMgsCH.js → apply-layout-DWTxIKYs.js} +1 -1
- package/dist/ui/assets/{apps-BaBqMpf9.js → apps-CDrFK--r.js} +1 -1
- package/dist/ui/assets/azure-openai-BCHBeybM.js +18 -0
- package/dist/ui/assets/azure-openai-C1aiXjjQ.js +18 -0
- package/dist/ui/assets/{azure-openai-responses-DUMDrZ29.js → azure-openai-responses-BNbgkULn.js} +1 -1
- package/dist/ui/assets/{azure-openai-responses-BcoOaRCx.js → azure-openai-responses-BULcSJeo.js} +1 -1
- package/dist/ui/assets/{bedrock-camp-LeceEQbU.js → bedrock-camp-9Mg_YE1C.js} +1 -1
- package/dist/ui/assets/{bedrock-camp-BcJEC3Pg.js → bedrock-camp-DP3Gfbz7.js} +1 -1
- package/dist/ui/assets/{browser-DdY1FBRp.js → browser-DGwroBSO.js} +3 -3
- package/dist/ui/assets/{bsh-watchdog-GrjFkpDG.js → bsh-watchdog--Df_ThJG.js} +1 -1
- package/dist/ui/assets/{cdp-ByIHQG_1.js → cdp-BzUC7d2h.js} +1 -1
- package/dist/ui/assets/{cerebras-DCOB1GIn.js → cerebras-BWY_xN7G.js} +1 -1
- package/dist/ui/assets/{cerebras-Oyxkgl8K.js → cerebras-X5XOc6kT.js} +1 -1
- package/dist/ui/assets/{claude-model-version-Csn7RPVg.js → claude-model-version-BXR93nLt.js} +1 -1
- package/dist/ui/assets/claude-model-version-D6lCh6G7.js +2 -0
- package/dist/ui/assets/{composer-speech-Bqp4MnUW.js → composer-speech-Byuwd2QJ.js} +1 -1
- package/dist/ui/assets/{connect-surface-N7OhnOjG.js → connect-surface-BqfnkTNQ.js} +1 -1
- package/dist/ui/assets/{cost-command-BQWpaecs.js → cost-command-CwOkolbd.js} +57 -57
- package/dist/ui/assets/{dist-_7dnux20.js → dist-BmTb9jmr.js} +1 -1
- package/dist/ui/assets/{dist-D7yTTAcb.js → dist-BnDrtqYs.js} +1 -1
- package/dist/ui/assets/dist-CMD3ZuiV.js +1 -0
- package/dist/ui/assets/{dist-DTAqvnM4.js → dist-CV-6KpFS.js} +1 -1
- package/dist/ui/assets/dist-CWHNqkcj.js +1 -0
- package/dist/ui/assets/dist-CrVgSn_b.js +6 -0
- package/dist/ui/assets/dist-DkG8wgj1.js +23 -0
- package/dist/ui/assets/dist-N1MMHRNk.js +18 -0
- package/dist/ui/assets/dist-RekgwRC0.js +12 -0
- package/dist/ui/assets/{dist-B4LJzMVB.js → dist-kBT87Ea7.js} +11 -11
- package/dist/ui/assets/{ensure-speech-assets-CO3wuKjp.js → ensure-speech-assets-Hv5Jwof_.js} +1 -1
- package/dist/ui/assets/{es-BDNIRkLU.js → es-BLFevQz4.js} +5 -5
- package/dist/ui/assets/{esbuild-wasm-DUOZmSly.js → esbuild-wasm-Dl3vgXvq.js} +2 -2
- package/dist/ui/assets/esp8266-1y0C3qJ1.js +1 -0
- package/dist/ui/assets/esptool-operations-CiccBbBW.js +12 -0
- package/dist/ui/assets/esptool-operations-lUvXx3gs.js +13 -0
- package/dist/ui/assets/{follower-navigate-watcher-Dd46El3D.js → follower-navigate-watcher-DRFF6ll0.js} +1 -1
- package/dist/ui/assets/fs-qMMHgiDM.js +2 -0
- package/dist/ui/assets/{fs-BNz_JyUR.js → fs-tsCmhLpU.js} +1 -1
- package/dist/ui/assets/github-CLAenO0m.js +2 -0
- package/dist/ui/assets/github-TenSKQL4.js +1 -0
- package/dist/ui/assets/{github-copilot-DiPxhMir.js → github-copilot-B-pJOojX.js} +1 -1
- package/dist/ui/assets/github-copilot-CvxZKmtr.js +2 -0
- package/dist/ui/assets/{github-install-CZSoNGFR.js → github-install-CSrLhUFy.js} +1 -1
- package/dist/ui/assets/{github-zip-CrdkhxjH.js → github-zip-KaxQyKKS.js} +1 -1
- package/dist/ui/assets/{google-generative-ai-Rjh7hNBV.js → google-generative-ai-DEMR2Ygt.js} +1 -1
- package/dist/ui/assets/{google-generative-ai-Dxo91M3n.js → google-generative-ai-ZQ9beFyW.js} +1 -1
- package/dist/ui/assets/{google-shared-DQJPCU3d.js → google-shared-B7H0ZrH8.js} +6 -6
- package/dist/ui/assets/google-shared-REamLvEm.js +11 -0
- package/dist/ui/assets/{google-vertex-DEwkNZJm.js → google-vertex-0C6GT5h4.js} +1 -1
- package/dist/ui/assets/{google-vertex-61Jj0dk6.js → google-vertex-DsErHx7o.js} +1 -1
- package/dist/ui/assets/handoff-link-BObMRgsx.js +1 -0
- package/dist/ui/assets/{hear-Co4TqejW.js → hear-zfLnACrB.js} +1 -1
- package/dist/ui/assets/{installer-CufDPCfO.js → installer-VcJEC2uC.js} +1 -1
- package/dist/ui/assets/{isomorphic-git-BAj-fLD-.js → isomorphic-git-WdgG3efW.js} +6 -6
- package/dist/ui/assets/js-realm-worker-CXQhPnY0.js +40 -0
- package/dist/ui/assets/{kernel-worker-DyoLnIZO.js → kernel-worker-BpjE-7BD.js} +421 -428
- package/dist/ui/assets/kokoro-BkJ3NLgd.js +4 -0
- package/dist/ui/assets/{legacy-api-aliases-oJPAvhVV.js → legacy-api-aliases-BYDhiWyY.js} +1 -1
- package/dist/ui/assets/{legacy-api-aliases-BnRqMAef.js → legacy-api-aliases-Dh4ciP2O.js} +1 -1
- package/dist/ui/assets/{libesm-BI4UHVqp.js → libesm-BypnjKEL.js} +1 -1
- package/dist/ui/assets/{libesm-zfj8k-QN.js → libesm-CSMdpGMF.js} +1 -1
- package/dist/ui/assets/lick-manager-CYlek4qq.js +2 -0
- package/dist/ui/assets/{lick-ws-bridge-yklVm5en.js → lick-ws-bridge-CdCpPLQn.js} +1 -1
- package/dist/ui/assets/{local-llm-DNFbzXTw.js → local-llm-D5B7umV1.js} +1 -1
- package/dist/ui/assets/{local-llm-DOnsCe6c.js → local-llm-onyoDvHB.js} +1 -1
- package/dist/ui/assets/magick-wasm-266b8ntc.js +43 -0
- package/dist/ui/assets/main-DjAHuk3R.js +22 -0
- package/dist/ui/assets/{main-cherry-3UVAQhqV.js → main-cherry-C6fqCnLL.js} +1 -1
- package/dist/ui/assets/{mount-DhhlMZMN.js → mount-BcopcDTf.js} +1 -1
- package/dist/ui/assets/mount-Cr-j5Qvu.js +2 -0
- package/dist/ui/assets/{mount-recovery-Dbd9EVjz.js → mount-recovery-DnWemQVb.js} +1 -1
- package/dist/ui/assets/{navigation-watcher-OPbGCby9.js → navigation-watcher-DrWMx-B4.js} +1 -1
- package/dist/ui/assets/new-session-DagG-ZZy.js +2 -0
- package/dist/ui/assets/oauth-bootstrap-CDgbPc25.js +2 -0
- package/dist/ui/assets/onboarding-orchestrator-DwBmySbw.js +1 -0
- package/dist/ui/assets/openai-BKEGagiR.js +17 -0
- package/dist/ui/assets/openai-Bgt_f1Dp.js +17 -0
- package/dist/ui/assets/{openai-codex-BI5-lt7L.js → openai-codex-B8nK05u1.js} +1 -1
- package/dist/ui/assets/openai-codex-CFHJKZXk.js +1 -0
- package/dist/ui/assets/{openai-codex-responses-CPOJeFUY.js → openai-codex-responses-C-nzMgox.js} +1 -1
- package/dist/ui/assets/{openai-codex-responses-jQR19NyX.js → openai-codex-responses-CG4v_H6T.js} +1 -1
- package/dist/ui/assets/{openai-completions-DGOcowq8.js → openai-completions-CIRx7G9l.js} +2 -2
- package/dist/ui/assets/{openai-completions-DGZFJo5D.js → openai-completions-ojba8VM0.js} +2 -2
- package/dist/ui/assets/{openai-responses-CDTdSIhv.js → openai-responses-BDRcKCF5.js} +1 -1
- package/dist/ui/assets/{openai-responses-bnETPgx9.js → openai-responses-DzwaJ-X-.js} +1 -1
- package/dist/ui/assets/openai-responses-shared-BjAQ1eIE.js +10 -0
- package/dist/ui/assets/openai-responses-shared-Dg_yfxea.js +10 -0
- package/dist/ui/assets/{openrouter-DZhpGJA4.js → openrouter-BQXiRTOg.js} +1 -1
- package/dist/ui/assets/openrouter-brhW7dHW.js +1 -0
- package/dist/ui/assets/{openrouter-images-C93KT7V_.js → openrouter-images-BAtqv3Im.js} +1 -1
- package/dist/ui/assets/{openrouter-images-CiM-JPBO.js → openrouter-images-Du3tMEQa.js} +1 -1
- package/dist/ui/assets/openrouter-oauth-DQ7iHoUX.js +1 -0
- package/dist/ui/assets/{openrouter-oauth-iFmYGgcr.js → openrouter-oauth-DuIS_qNZ.js} +1 -1
- package/dist/ui/assets/panel-rpc-handlers-BBgO_HM3.js +2 -0
- package/dist/ui/assets/panelize-shell-DpfBeau6.js +4 -0
- package/dist/ui/assets/pdfjs-DAWky37A.js +100 -0
- package/dist/ui/assets/{provider-CauMmJra.js → provider-D1IQTDOu.js} +1 -1
- package/dist/ui/assets/provider-VbLD3Pa_.js +2 -0
- package/dist/ui/assets/{provider-settings-CDR9tmFe.js → provider-settings-D24NB2-U.js} +1 -1
- package/dist/ui/assets/provider-store-access-CFkv-yrf.js +1 -0
- package/dist/ui/assets/provider-store-access-Dh0tBZso.js +1 -0
- package/dist/ui/assets/providers-CZ_sFfrt.js +2 -0
- package/dist/ui/assets/{providers-DS7U7ou8.js → providers-PfyMAay1.js} +1 -1
- package/dist/ui/assets/{py-realm-worker-B2OTI7Xc.js → py-realm-worker-D1gqcTkl.js} +2 -2
- package/dist/ui/assets/{pyodide-CkJHMMSo.js → pyodide-D43YUXvd.js} +2 -2
- package/dist/ui/assets/{quick-llm-DSQHsD_0.js → quick-llm-drlxgkUg.js} +1 -1
- package/dist/ui/assets/{recovery-screen-dGlemlkP.js → recovery-screen-BccxAWe7.js} +1 -1
- package/dist/ui/assets/{redirect-uri-BOpxbXbd.js → redirect-uri-AfF6uLvV.js} +1 -1
- package/dist/ui/assets/remote-cdp-transport-DeDqT7I4.js +1 -0
- package/dist/ui/assets/remote-sprinkle-vfs-CawR6gXx.js +1 -0
- package/dist/ui/assets/{remote-terminal-view-BNWZWMBC.js → remote-terminal-view-D2bRNJcS.js} +2 -2
- package/dist/ui/assets/{run-Cll4MnAK.js → run-BIKu737n.js} +1 -1
- package/dist/ui/assets/safe-buffer-OLJ0qaLt.js +12 -0
- package/dist/ui/assets/safe-buffer-iah92gQe.js +1 -0
- package/dist/ui/assets/{setup-feature-flags-remote-rcKrPHk7.js → setup-feature-flags-remote-Dxg6pIkQ.js} +1 -1
- package/dist/ui/assets/shared-B9N4MZd0.js +1 -0
- package/dist/ui/assets/shared-CPVZc-MN.js +4 -0
- package/dist/ui/assets/sidecar-repair-DCvPqdWE.js +1 -0
- package/dist/ui/assets/{skills-0Do2e7wj.js → skills-Cc4T1Cfp.js} +1 -1
- package/dist/ui/assets/{slicc-diff-DhGIKKqP.js → slicc-diff-DRjxoBYz.js} +1 -1
- package/dist/ui/assets/slicc-editor-D-eO_pjd.js +23 -0
- package/dist/ui/assets/slicc-editor-Sdfe-_x_.js +1 -0
- package/dist/ui/assets/slicc-version-CzfOvAya.js +1 -0
- package/dist/ui/assets/speak-BsVaFA0Z.js +3 -0
- package/dist/ui/assets/{sprinkle-bridge-C4qw-DTw.js → sprinkle-bridge-e00Na2NA.js} +1 -1
- package/dist/ui/assets/{sprinkle-manager-B5T2quSt.js → sprinkle-manager-BqdBktzt.js} +1 -1
- package/dist/ui/assets/{sprinkle-renderer-D64E-W2o.js → sprinkle-renderer-C9L5ZRvl.js} +2 -2
- package/dist/ui/assets/{sql-wasm-DO685FZu.js → sql-wasm-B7K7OCuB.js} +1 -1
- package/dist/ui/assets/{state-BrCP8Eff.js → state-B8PB53C0.js} +1 -1
- package/dist/ui/assets/{store-bEWnkux0.js → store-BsTL1Wgg.js} +1 -1
- package/dist/ui/assets/{store-C2gM1M-9.js → store-SXMbC-35.js} +1 -1
- package/dist/ui/assets/{sudo-D0ZG1KJr.js → sudo-Blo41kLx.js} +1 -1
- package/dist/ui/assets/sync-dialog-yRY0wRJj.js +1 -0
- package/dist/ui/assets/{temperature-support-B4x2xaWY.js → temperature-support-BVrwHxWv.js} +1 -1
- package/dist/ui/assets/{temperature-support-Cpml9LfI.js → temperature-support-LrmsX3ix.js} +1 -1
- package/dist/ui/assets/{transformers-env-HIDS8utb.js → transformers-env-_JNZLFlo.js} +1 -1
- package/dist/ui/assets/transformers.web-B0gi9Hor.js +39 -0
- package/dist/ui/assets/tray-leader-Mq6HIneb.js +1 -0
- package/dist/ui/assets/{upgrade-detection-Ckesn3Ns.js → upgrade-detection-DqD1aedt.js} +1 -1
- package/dist/ui/assets/voice-reply-B-I-XncI.js +1 -0
- package/dist/ui/assets/wc-attach-DgJVZRem.js +13 -0
- package/dist/ui/assets/wc-extension-b7ONOPn6.js +2 -0
- package/dist/ui/assets/wc-float-label-d3I12c8W.js +1 -0
- package/dist/ui/assets/{wc-floatbar-online-tsTifrU7.js → wc-floatbar-online-CFeU9jju.js} +1 -1
- package/dist/ui/assets/wc-follower-BU7l80Bf.js +17 -0
- package/dist/ui/assets/wc-follower-oauth-DIH7qpbt.js +5 -0
- package/dist/ui/assets/wc-live-DL5TcdQ7.js +399 -0
- package/dist/ui/assets/wc-nav-DjOpEDo-.js +2 -0
- package/dist/ui/assets/wc-onboarding-BeunqMQZ.js +2 -0
- package/dist/ui/assets/{wc-permissions-CEmFmdBe.js → wc-permissions-WjSZrbPa.js} +2 -2
- package/dist/ui/assets/{wc-placeholder-C1LDJQR7.js → wc-placeholder-mYgmrH75.js} +3 -3
- package/dist/ui/assets/{wc-settings-PtFpnkee.js → wc-settings-JfsyJgL9.js} +3 -3
- package/dist/ui/assets/{src-B-encLtu.js → wc-shell-B7yZ6nn6.js} +304 -161
- package/dist/ui/assets/{wc-shortcut-config-w6fJ0bVB.js → wc-shortcut-config-CRticSXA.js} +2 -2
- package/dist/ui/assets/{wc-sprinkles-CeAUkWME.js → wc-sprinkles-D-DWMPsX.js} +2 -2
- package/dist/ui/assets/wc-transcript-export-DVjtNvuR.js +2 -0
- package/dist/ui/assets/wc-tray-D6joGkUe.js +2 -0
- package/dist/ui/assets/welcome-detection-CEmFgOCI.js +1 -0
- package/dist/ui/assets/{whisper-session-DzV9Jmfi.js → whisper-session-Ba-J0yyJ.js} +2 -2
- package/dist/ui/assets/{xai-grok-DRbKtbML.js → xai-grok-DHRw8xLj.js} +1 -1
- package/dist/ui/assets/xai-grok-DIhtpBYR.js +1 -0
- package/dist/ui/assets/xterm-B5LH8GIb.css +1 -0
- package/dist/ui/assets/xterm-C3BHN0de.js +16 -0
- package/dist/ui/index.html +8 -11
- package/dist/ui/packages/webapp/index.html +8 -11
- package/dist/ui/slicc-diff.js +1 -1
- package/dist/ui/slicc-editor.js +1 -1
- package/package.json +2 -2
- package/dist/ui/assets/__vite-browser-external-CwfFUl-x.js +0 -1
- package/dist/ui/assets/adobe-DeM_oCMe.js +0 -2
- package/dist/ui/assets/agent-message-to-chat-_cvF5A5g.js +0 -1
- package/dist/ui/assets/agent-panels-B92KQapO.js +0 -1
- package/dist/ui/assets/azure-openai-B2VLKBwJ.js +0 -18
- package/dist/ui/assets/azure-openai-tc52REpx.js +0 -18
- package/dist/ui/assets/backend-local-1YuE96fx.js +0 -1
- package/dist/ui/assets/chat-session-store-pWb1-jNp.js +0 -1
- package/dist/ui/assets/claude-model-version-DoVrYsKi.js +0 -2
- package/dist/ui/assets/db-cKsBsMMN.js +0 -1
- package/dist/ui/assets/dictation-priming-CNllGgNq.js +0 -1
- package/dist/ui/assets/dip-rCM_6Bc6.js +0 -233
- package/dist/ui/assets/dist-B6HZAA0r.js +0 -1
- package/dist/ui/assets/dist-BHvDPTv0.js +0 -1
- package/dist/ui/assets/dist-C56QxoYU.js +0 -18
- package/dist/ui/assets/dist-COLaZOxM.js +0 -23
- package/dist/ui/assets/dist-CPNmKU6m.js +0 -12
- package/dist/ui/assets/dist-Cew647MY.js +0 -12
- package/dist/ui/assets/dist-mxmkfALf.js +0 -6
- package/dist/ui/assets/esptool-operations-BmdosN6N.js +0 -13
- package/dist/ui/assets/esptool-operations-CbgLIJzi.js +0 -12
- package/dist/ui/assets/export-provider-BEHTjSYw.js +0 -1
- package/dist/ui/assets/follower-presentation-DqBw0YiV.js +0 -1
- package/dist/ui/assets/fs-C6heN6Io.js +0 -2
- package/dist/ui/assets/github-BES17MG4.js +0 -2
- package/dist/ui/assets/github-BnrwrtRn.js +0 -1
- package/dist/ui/assets/github-copilot-CzZSdNg_.js +0 -2
- package/dist/ui/assets/google-shared-CzJgTu-P.js +0 -11
- package/dist/ui/assets/handoff-link-BM4ctkE8.js +0 -1
- package/dist/ui/assets/host-command-zx0pt9Np.js +0 -1
- package/dist/ui/assets/js-realm-worker-D_8dhTFA.js +0 -40
- package/dist/ui/assets/kokoro-Bs5vU5OU.js +0 -4
- package/dist/ui/assets/layout-schema-m9_VAwOw.js +0 -1
- package/dist/ui/assets/leader-session-events-Iq9N1w56.js +0 -1
- package/dist/ui/assets/lick-manager-DFmMezV-.js +0 -2
- package/dist/ui/assets/magick-wasm-BpzBj-21.js +0 -43
- package/dist/ui/assets/main-CPLi98yu.js +0 -22
- package/dist/ui/assets/mount-CvVyowQ-.js +0 -2
- package/dist/ui/assets/new-session-BUxTN19q.js +0 -2
- package/dist/ui/assets/oauth-bootstrap-BnctKs3I.js +0 -2
- package/dist/ui/assets/onboarding-orchestrator-BF4m_3Ig.js +0 -1
- package/dist/ui/assets/openai-CjBvzZcB.js +0 -17
- package/dist/ui/assets/openai-ZcrxEOGB.js +0 -17
- package/dist/ui/assets/openai-codex-ad3likLF.js +0 -1
- package/dist/ui/assets/openai-responses-shared-ChgvRZ74.js +0 -10
- package/dist/ui/assets/openai-responses-shared-DqJbHrek.js +0 -10
- package/dist/ui/assets/openrouter-BfwBtJ0a.js +0 -1
- package/dist/ui/assets/openrouter-oauth-D1ocgCDw.js +0 -1
- package/dist/ui/assets/panel-registry-CJdOibpf.js +0 -1
- package/dist/ui/assets/panel-rpc-handlers-Dj-UnwwI.js +0 -2
- package/dist/ui/assets/panelize-shell-Dfx0Qk97.js +0 -4
- package/dist/ui/assets/pdfjs-BspLIDsM.js +0 -100
- package/dist/ui/assets/provider-3zYFx7pL.js +0 -2
- package/dist/ui/assets/provider-settings-CZ97KB3C.js +0 -2
- package/dist/ui/assets/provider-store-access-DvHfXiAa.js +0 -2
- package/dist/ui/assets/provider-store-access-escWLliN.js +0 -1
- package/dist/ui/assets/providers-DJA67z1N.js +0 -2
- package/dist/ui/assets/remote-cdp-transport-CgOXLjZ8.js +0 -1
- package/dist/ui/assets/remote-sprinkle-vfs-e81pZJKo.js +0 -1
- package/dist/ui/assets/safe-buffer-B2wnAhUx.js +0 -12
- package/dist/ui/assets/safe-buffer-BwTVRVVo.js +0 -1
- package/dist/ui/assets/session-freezer-BgO7tLUp.js +0 -162
- package/dist/ui/assets/setup-standalone-prelude-50scBzpK.js +0 -2
- package/dist/ui/assets/setup-sudo-Ce_APR8D.js +0 -2
- package/dist/ui/assets/shared-6HJLEwgI.js +0 -1
- package/dist/ui/assets/shared-BzvvjAZt.js +0 -4
- package/dist/ui/assets/sidecar-repair-431vRT2V.js +0 -1
- package/dist/ui/assets/slicc-editor-CVftccS9.js +0 -1
- package/dist/ui/assets/slicc-editor-DsHp_in-.js +0 -12
- package/dist/ui/assets/slicc-version-qJjMq-6R.js +0 -1
- package/dist/ui/assets/speak-KEFd3n_I.js +0 -3
- package/dist/ui/assets/sync-dialog-ACgl0n-p.js +0 -1
- package/dist/ui/assets/timestamp-preference-sKwBl5I8.js +0 -2
- package/dist/ui/assets/transformers.web-Cg_-cFJu.js +0 -39
- package/dist/ui/assets/tray-leader-iVJTGwuf.js +0 -1
- package/dist/ui/assets/tray-sync-protocol-BZ5yhJH9.js +0 -1
- package/dist/ui/assets/tray-sync-protocol-DV_QG_Ey.js +0 -1
- package/dist/ui/assets/trusted-layer-ghPA1ENf.js +0 -1
- package/dist/ui/assets/voice-reply-DaVk8H0o.js +0 -1
- package/dist/ui/assets/wc-attach-3I9pOCPA.js +0 -13
- package/dist/ui/assets/wc-extension-D1gzObu-.js +0 -2
- package/dist/ui/assets/wc-float-label-CCMo81Ds.js +0 -1
- package/dist/ui/assets/wc-follower-DrCJN-aK.js +0 -17
- package/dist/ui/assets/wc-follower-oauth-Dw0qOLsI.js +0 -5
- package/dist/ui/assets/wc-live-qc9mrCs3.js +0 -8
- package/dist/ui/assets/wc-nav-CysORJLz.js +0 -2
- package/dist/ui/assets/wc-onboarding-COhEMI0E.js +0 -2
- package/dist/ui/assets/wc-scoop-color-ShF3p7L9.js +0 -1
- package/dist/ui/assets/wc-shell-lFwQe30J.js +0 -119
- package/dist/ui/assets/wc-shortcuts-GiPteshM.js +0 -26
- package/dist/ui/assets/wc-transcript-export-DKIleW7-.js +0 -2
- package/dist/ui/assets/wc-tray-_dof-pAl.js +0 -2
- package/dist/ui/assets/welcome-detection-iVN_xL76.js +0 -1
- package/dist/ui/assets/xai-grok-BnSpWJjV.js +0 -1
- package/dist/ui/assets/xterm-BSL5rRqA.js +0 -18
- package/dist/ui/assets/xterm-BmfB5bmM.css +0 -1
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import{b as e,g as t}from"./account-store-DhN2-vXh.js";import{a as n}from"./diagnostics-DN_idNHx.js";import{t as r}from"./models-4WTk3EBD.js";import{u as i}from"./claude-model-version-BXR93nLt.js";import{i as a,t as o}from"./transform-messages-DZg9zDcV.js";function s(e,t,n,r,i){if(r===`m`)throw TypeError(`Private method is not writable`);if(r===`a`&&!i)throw TypeError(`Private accessor was defined without a setter`);if(typeof t==`function`?e!==t||!i:!t.has(e))throw TypeError(`Cannot write private member to an object whose class did not declare it`);return r===`a`?i.call(e,n):i?i.value=n:t.set(e,n),n}function c(e,t,n,r){if(n===`a`&&!r)throw TypeError(`Private accessor was defined without a getter`);if(typeof t==`function`?e!==t||!r:!t.has(e))throw TypeError(`Cannot read private member from an object whose class did not declare it`);return n===`m`?r:n===`a`?r.call(e):r?r.value:t.get(e)}let l=function(){let{crypto:e}=globalThis;if(e?.randomUUID)return l=e.randomUUID.bind(e),e.randomUUID();let t=new Uint8Array(1),n=e?()=>e.getRandomValues(t)[0]:()=>Math.random()*255&255;return`10000000-1000-4000-8000-100000000000`.replace(/[018]/g,e=>(e^n()&15>>e/4).toString(16))};function u(e){return typeof e==`object`&&!!e&&(`name`in e&&e.name===`AbortError`||`message`in e&&String(e.message).includes(`FetchRequestCanceledException`))}const d=e=>{if(e instanceof Error)return e;if(typeof e==`object`&&e){try{if(Object.prototype.toString.call(e)===`[object Error]`){let t=Error(e.message,e.cause?{cause:e.cause}:{});return e.stack&&(t.stack=e.stack),e.cause&&!t.cause&&(t.cause=e.cause),e.name&&(t.name=e.name),t}}catch{}try{return Error(JSON.stringify(e))}catch{}}return Error(e)};var f=class extends Error{},p=class e extends f{constructor(t,n,r,i){super(`${e.makeMessage(t,n,r)}`),this.status=t,this.headers=i,this.requestID=i?.get(`x-request-id`),this.error=n;let a=n;this.code=a?.code,this.param=a?.param,this.type=a?.type}static makeMessage(e,t,n){let r=t?.message?typeof t.message==`string`?t.message:JSON.stringify(t.message):t?JSON.stringify(t):n;return e&&r?`${e} ${r}`:e?`${e} status code (no body)`:r||`(no status code or body)`}static generate(t,n,r,i){if(!t||!i)return new h({message:r,cause:d(n)});let a=n?.error;return t===400?new _(t,a,r,i):t===401?new v(t,a,r,i):t===403?new y(t,a,r,i):t===404?new b(t,a,r,i):t===409?new x(t,a,r,i):t===422?new ee(t,a,r,i):t===429?new te(t,a,r,i):t>=500?new ne(t,a,r,i):new e(t,a,r,i)}},m=class extends p{constructor({message:e}={}){super(void 0,void 0,e||`Request was aborted.`,void 0)}},h=class extends p{constructor({message:e,cause:t}){super(void 0,void 0,e||`Connection error.`,void 0),t&&(this.cause=t)}},g=class extends h{constructor({message:e}={}){super({message:e??`Request timed out.`})}},_=class extends p{},v=class extends p{},y=class extends p{},b=class extends p{},x=class extends p{},ee=class extends p{},te=class extends p{},ne=class extends p{},re=class extends f{constructor(){super(`Could not parse response content as the length limit was reached`)}},ie=class extends f{constructor(){super(`Could not parse response content as the request was rejected by the content filter`)}},ae=class extends Error{constructor(e){super(e)}},oe=class extends p{constructor(e,t,n){let r=`OAuth2 authentication error`,i;if(t&&typeof t==`object`){let e=t;i=e.error;let n=e.error_description;n&&typeof n==`string`?r=n:i&&(r=i)}super(e,t,r,n),this.error_code=i}},se=class extends f{constructor(e,t,n){super(e),this.provider=t,this.cause=n}};const ce=/^[a-z][a-z0-9+.-]*:/i,le=e=>ce.test(e);let S=e=>(S=Array.isArray,S(e)),ue=S;function de(e){return typeof e==`object`?e??{}:{}}function fe(e){if(!e)return!0;for(let t in e)return!1;return!0}function pe(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function C(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}const me=(e,t)=>{if(typeof t!=`number`||!Number.isInteger(t))throw new f(`${e} must be an integer`);if(t<0)throw new f(`${e} must be a positive integer`);return t},he=e=>{try{return JSON.parse(e)}catch{return}},ge=e=>new Promise(t=>setTimeout(t,e));function _e(){if(typeof fetch<`u`)return fetch;throw Error("`fetch` is not defined as a global; Either pass `fetch` to the client, `new OpenAI({ fetch })` or polyfill the global, `globalThis.fetch = fetch`")}function ve(...e){let t=globalThis.ReadableStream;if(t===void 0)throw Error("`ReadableStream` is not defined as a global; You will need to polyfill it, `globalThis.ReadableStream = ReadableStream`");return new t(...e)}function ye(e){let t=Symbol.asyncIterator in e?e[Symbol.asyncIterator]():e[Symbol.iterator]();return ve({start(){},async pull(e){let{done:n,value:r}=await t.next();n?e.close():e.enqueue(r)},async cancel(){await t.return?.()}})}function be(e){if(e[Symbol.asyncIterator])return e;let t=e.getReader();return{async next(){try{let e=await t.read();return e?.done&&t.releaseLock(),e}catch(e){throw t.releaseLock(),e}},async return(){let e=t.cancel();return t.releaseLock(),await e,{done:!0,value:void 0}},[Symbol.asyncIterator](){return this}}}async function xe(e){if(typeof e!=`object`||!e)return;if(e[Symbol.asyncIterator]){await e[Symbol.asyncIterator]().return?.();return}let t=e.getReader(),n=t.cancel();t.releaseLock(),await n}let Se;function w(e){let t;return(Se??=(t=new globalThis.TextEncoder,t.encode.bind(t)))(e)}let Ce;function we(e){let t;return(Ce??=(t=new globalThis.TextDecoder,t.decode.bind(t)))(e)}var Te,T,E,D,O,Ee,De;const Oe=65536;var ke=class{constructor(){Te.add(this),T.set(this,void 0),E.set(this,void 0),D.set(this,void 0),O.set(this,void 0),Ee.set(this,void 0),s(this,T,new Uint8Array,`f`),s(this,E,0,`f`),s(this,D,0,`f`),s(this,O,0,`f`),s(this,Ee,!1,`f`)}decode(e){if(e==null)return[];let t;if(t=e instanceof ArrayBuffer?new Uint8Array(e):typeof e==`string`?w(e):e,t.length===0||c(this,Ee,`f`)&&(s(this,Ee,!1,`f`),t[0]===10&&(t=t.subarray(1)),t.length===0))return[];c(this,Te,`m`,De).call(this,t);let n=[],r;for(;(r=Ae(c(this,T,`f`),c(this,O,`f`),c(this,D,`f`)))!=null;){let e=we(c(this,T,`f`).subarray(c(this,E,`f`),r.preceding));n.push(e),s(this,E,r.index,`f`),r.carriage&&(c(this,E,`f`)<c(this,D,`f`)&&c(this,T,`f`)[c(this,E,`f`)]===10?s(this,E,c(this,E,`f`)+1,`f`):c(this,E,`f`)===c(this,D,`f`)&&s(this,Ee,!0,`f`)),s(this,O,c(this,E,`f`),`f`)}if(s(this,O,c(this,D,`f`),`f`),c(this,E,`f`)===c(this,D,`f`))s(this,E,0,`f`),s(this,D,0,`f`),s(this,O,0,`f`),c(this,T,`f`).length>Oe&&s(this,T,new Uint8Array,`f`);else if(n.length>0&&c(this,T,`f`).length>Oe){let e=c(this,D,`f`)-c(this,E,`f`);if(e<=Oe||c(this,T,`f`).length>e*4){let t=e<=Oe?Math.min(Math.max(e*2,256),Oe):e*2,n=new Uint8Array(t);n.set(c(this,T,`f`).subarray(c(this,E,`f`),c(this,D,`f`))),s(this,T,n,`f`),s(this,E,0,`f`),s(this,D,e,`f`),s(this,O,e,`f`)}}return n}flush(){return s(this,Ee,!1,`f`),c(this,E,`f`)===c(this,D,`f`)?[]:this.decode(`
|
|
2
|
+
`)}};T=new WeakMap,E=new WeakMap,D=new WeakMap,O=new WeakMap,Ee=new WeakMap,Te=new WeakSet,De=function(e){if(c(this,D,`f`)+e.length>c(this,T,`f`).length){let t=c(this,D,`f`)-c(this,E,`f`);if(c(this,E,`f`)>=c(this,T,`f`).length/2&&t+e.length<=c(this,T,`f`).length)c(this,T,`f`).copyWithin(0,c(this,E,`f`),c(this,D,`f`));else{let n=Math.max(c(this,T,`f`).length*2,t+e.length,256),r=new Uint8Array(n);r.set(c(this,T,`f`).subarray(c(this,E,`f`),c(this,D,`f`))),s(this,T,r,`f`)}s(this,O,c(this,O,`f`)-c(this,E,`f`),`f`),s(this,D,t,`f`),s(this,E,0,`f`)}c(this,T,`f`).set(e,c(this,D,`f`)),s(this,D,c(this,D,`f`)+e.length,`f`)},ke.NEWLINE_CHARS=new Set([`
|
|
3
|
+
`,`\r`]),ke.NEWLINE_REGEXP=/\r\n|[\n\r]/g;function Ae(e,t,n){for(let r=t;r<n;r++){if(e[r]===10)return{preceding:r,index:r+1,carriage:!1};if(e[r]===13)return{preceding:r,index:r+1,carriage:!0}}return null}function je(e){for(let t=0;t<e.length-1;t++){let n=Me(e,t);if(n>0){let r=t+n,i=Me(e,r);if(i>0)return r+i}}return-1}function Me(e,t){return e[t]===10?1:e[t]===13?e[t+1]===10?2:1:0}const Ne={off:0,error:200,warn:300,info:400,debug:500},Pe=(e,t,n)=>{if(e){if(pe(Ne,e))return e;k(n).warn(`${t} was set to ${JSON.stringify(e)}, expected one of ${JSON.stringify(Object.keys(Ne))}`)}};function Fe(){}function Ie(e,t,n){return!t||Ne[e]>Ne[n]?Fe:t[e].bind(t)}const Le={error:Fe,warn:Fe,info:Fe,debug:Fe};let Re=new WeakMap;function k(e){let t=e.logger,n=e.logLevel??`off`;if(!t)return Le;let r=Re.get(t);if(r&&r[0]===n)return r[1];let i={error:Ie(`error`,t,n),warn:Ie(`warn`,t,n),info:Ie(`info`,t,n),debug:Ie(`debug`,t,n)};return Re.set(t,[n,i]),i}const ze=e=>(e.options&&(e.options={...e.options},delete e.options.headers),e.headers&&=Object.fromEntries((e.headers instanceof Headers?[...e.headers]:Object.entries(e.headers)).map(([e,t])=>[e,e.toLowerCase()===`authorization`||e.toLowerCase()===`api-key`||e.toLowerCase()===`x-api-key`||e.toLowerCase()===`x-amz-security-token`||e.toLowerCase()===`cookie`||e.toLowerCase()===`set-cookie`?`***`:t])),`retryOfRequestLogID`in e&&(e.retryOfRequestLogID&&(e.retryOf=e.retryOfRequestLogID),delete e.retryOfRequestLogID),e);var Be,Ve=class e{constructor(e,t,n){Be.set(this,void 0),this.iterator=e,this.controller=t,s(this,Be,n,`f`)}static fromSSEResponse(t,n,r,i){let a=!1,o=r?k(r):console;async function*s(){if(a)throw new f("Cannot iterate over a consumed stream, use `.tee()` to split the stream.");a=!0;let e=!1,r=!1;try{for await(let e of He(t,n)){if(e.data.startsWith(`[DONE]`)){r=!0;break}if(e.event===null||!e.event.startsWith(`thread.`)){let n;try{n=JSON.parse(e.data)}catch(t){throw o.error(`Could not parse message into JSON:`,e.data),o.error(`From chunk:`,e.raw),t}if(n&&n.error)throw new p(void 0,n.error,void 0,t.headers);yield i?{event:e.event,data:n}:n}else{let t;try{t=JSON.parse(e.data)}catch(t){throw console.error(`Could not parse message into JSON:`,e.data),console.error(`From chunk:`,e.raw),t}if(e.event===`error`)throw new p(void 0,t.error,t.message,void 0);yield{event:e.event,data:t}}}e=!0}catch(e){if(r||u(e)||n.signal.aborted&&e===n.signal.reason)return;throw e}finally{e||n.abort()}}return new e(s,n,r)}static fromReadableStream(t,n,r){let i=!1;async function*a(){let e=new ke,r=t.getReader(),i=!1,a,o=()=>{a??=r.cancel(),a.catch(()=>void 0)};n.signal.addEventListener(`abort`,o,{once:!0});try{if(n.signal.aborted){o();return}for(;;){let{value:t,done:a}=await r.read();if(a){i=!0;break}if(n.signal.aborted)return;for(let r of e.decode(t)){if(n.signal.aborted)return;yield r}}if(n.signal.aborted)return;for(let t of e.flush()){if(n.signal.aborted)return;yield t}}finally{n.signal.removeEventListener(`abort`,o),i||o(),r.releaseLock()}}async function*o(){if(i)throw new f("Cannot iterate over a consumed stream, use `.tee()` to split the stream.");i=!0;let e=!1;try{for await(let t of a())e||t&&(yield JSON.parse(t));e=!0}catch(e){if(n.signal.aborted||u(e))return;throw e}finally{e||n.abort()}}return new e(o,n,r)}[(Be=new WeakMap,Symbol.asyncIterator)](){return this.iterator()}tee(){let t=[],n=[],r=this.iterator(),i=e=>({next:()=>{if(e.length===0){let e=r.next();t.push(e),n.push(e)}return e.shift()}});return[new e(()=>i(t),this.controller,c(this,Be,`f`)),new e(()=>i(n),this.controller,c(this,Be,`f`))]}toReadableStream(){let e;return ve({start:async()=>{e=this[Symbol.asyncIterator]()},async pull(t){try{let{value:n,done:r}=await e.next();if(r)return t.close();let i=w(JSON.stringify(n)+`
|
|
4
|
+
`);t.enqueue(i)}catch(e){t.error(e)}},async cancel(){await e.return?.()}})}};async function*He(e,t){if(!e.body)throw t.abort(),globalThis.navigator!==void 0&&globalThis.navigator.product===`ReactNative`?new f(`The default react-native fetch implementation does not support streaming. Please use expo/fetch: https://docs.expo.dev/versions/latest/sdk/expo/#expofetch-api`):new f(`Attempted to iterate over a response with no body`);let n=new We,r=new ke,i=be(e.body);for await(let e of Ue(i))for(let t of r.decode(e)){let e=n.decode(t);e&&(yield e)}for(let e of r.flush()){let t=n.decode(e);t&&(yield t)}}async function*Ue(e){let t=new Uint8Array,n=0,r=0,i=0;for await(let a of e){if(a==null)continue;let e;if(e=a instanceof ArrayBuffer?new Uint8Array(a):typeof a==`string`?w(a):a,r+e.length>t.length){let a=r-n;if(n>=t.length/2&&a+e.length<=t.length)t.copyWithin(0,n,r);else{let i=new Uint8Array(Math.max(t.length*2,a+e.length));i.set(t.subarray(n,r)),t=i}i-=n,n=0,r=a}t.set(e,r),r+=e.length;let o;for(;(o=je(t.subarray(i,r)))!==-1;)o+=i,yield t.slice(n,o),n=o,i=n;i=Math.max(n,r-3)}r>n&&(yield t.slice(n,r))}var We=class{constructor(){this.event=null,this.data=[],this.chunks=[]}decode(e){if(e.endsWith(`\r`)&&(e=e.slice(0,-1)),!e){if(!this.event&&!this.data.length)return null;let e={event:this.event,data:this.data.join(`
|
|
5
|
+
`),raw:this.chunks};return this.event=null,this.data=[],this.chunks=[],e}if(this.chunks.push(e),e.startsWith(`:`))return null;let[t,,n]=Ge(e,`:`),r=n;return r.startsWith(` `)&&(r=r.slice(1)),t===`event`?this.event=r:t===`data`&&this.data.push(r),null}};function Ge(e,t){let n=e.indexOf(t);return n===-1?[e,``,``]:[e.slice(0,n),t,e.slice(n+t.length)]}async function Ke(e,t){let{response:n,requestLogID:r,retryOfRequestLogID:i,startTime:a}=t,o=await(async()=>{if(t.options.stream)return k(e).debug(`response`,n.status,n.url,n.headers,n.body),t.options.__streamClass?t.options.__streamClass.fromSSEResponse(n,t.controller,e,t.options.__synthesizeEventData):Ve.fromSSEResponse(n,t.controller,e,t.options.__synthesizeEventData);if(n.status===204)return null;if(t.options.__binaryResponse)return n;let r=n.headers.get(`content-type`)?.split(`;`)[0]?.trim();if(r?.includes(`application/json`)||r?.endsWith(`+json`)){if(n.headers.get(`content-length`)===`0`)return;let e=await n.text();return e?Je(JSON.parse(e),n):void 0}return await n.text()})().catch(e=>{throw qe(e,t.controller.signal)});return k(e).debug(`[${r}] response parsed`,ze({retryOfRequestLogID:i,url:n.url,status:n.status,body:o,durationMs:Date.now()-a})),o}function qe(e,t){if(!t.aborted||e!==t.reason||u(e))return e;let n=`This operation was aborted`,r=globalThis.DOMException;return typeof r==`function`?new r(n,`AbortError`):Object.assign(Error(n),{name:`AbortError`})}function Je(e,t){return!e||typeof e!=`object`||Array.isArray(e)?e:Object.defineProperty(e,"_request_id",{value:t.headers.get(`x-request-id`),enumerable:!1})}const Ye=`7.5.0`,Xe=()=>typeof window<`u`&&window.document!==void 0&&typeof navigator<`u`;function Ze(){return typeof Deno<`u`&&Deno.build!=null?`deno`:typeof EdgeRuntime<`u`?`edge`:Object.prototype.toString.call(globalThis.process===void 0?0:globalThis.process)===`[object process]`?`node`:`unknown`}const Qe=()=>{let e=Ze();if(e===`deno`)return{"X-Stainless-Lang":`js`,"X-Stainless-Package-Version":Ye,"X-Stainless-OS":tt(Deno.build.os),"X-Stainless-Arch":et(Deno.build.arch),"X-Stainless-Runtime":`deno`,"X-Stainless-Runtime-Version":typeof Deno.version==`string`?Deno.version:Deno.version?.deno??`unknown`};if(typeof EdgeRuntime<`u`)return{"X-Stainless-Lang":`js`,"X-Stainless-Package-Version":Ye,"X-Stainless-OS":`Unknown`,"X-Stainless-Arch":`other:${EdgeRuntime}`,"X-Stainless-Runtime":`edge`,"X-Stainless-Runtime-Version":globalThis.process.version};if(e===`node`)return{"X-Stainless-Lang":`js`,"X-Stainless-Package-Version":Ye,"X-Stainless-OS":tt(globalThis.process.platform??`unknown`),"X-Stainless-Arch":et(globalThis.process.arch??`unknown`),"X-Stainless-Runtime":`node`,"X-Stainless-Runtime-Version":globalThis.process.version??`unknown`};let t=$e();return t?{"X-Stainless-Lang":`js`,"X-Stainless-Package-Version":Ye,"X-Stainless-OS":`Unknown`,"X-Stainless-Arch":`unknown`,"X-Stainless-Runtime":`browser:${t.browser}`,"X-Stainless-Runtime-Version":t.version}:{"X-Stainless-Lang":`js`,"X-Stainless-Package-Version":Ye,"X-Stainless-OS":`Unknown`,"X-Stainless-Arch":`unknown`,"X-Stainless-Runtime":`unknown`,"X-Stainless-Runtime-Version":`unknown`}};function $e(){if(typeof navigator>`u`||!navigator)return null;for(let{key:e,pattern:t}of[{key:`edge`,pattern:/Edge(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:`ie`,pattern:/MSIE(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:`ie`,pattern:/Trident(?:.*rv\:(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:`chrome`,pattern:/Chrome(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:`firefox`,pattern:/Firefox(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:`safari`,pattern:/(?:Version\W+(\d+)\.(\d+)(?:\.(\d+))?)?(?:\W+Mobile\S*)?\W+Safari/}]){let n=t.exec(navigator.userAgent);if(n)return{browser:e,version:`${n[1]||0}.${n[2]||0}.${n[3]||0}`}}return null}const et=e=>e===`x32`?`x32`:e===`x86_64`||e===`x64`?`x64`:e===`arm`?`arm`:e===`aarch64`||e===`arm64`?`arm64`:e?`other:${e}`:`unknown`,tt=e=>(e=e.toLowerCase(),e.includes(`ios`)?`iOS`:e===`android`?`Android`:e===`darwin`?`MacOS`:e===`win32`?`Windows`:e===`freebsd`?`FreeBSD`:e===`openbsd`?`OpenBSD`:e===`linux`?`Linux`:e?`Other:${e}`:`Unknown`);let nt;const rt=()=>nt??=Qe(),it=({headers:e,body:t})=>({bodyHeaders:{"content-type":`application/json`},body:JSON.stringify(t)}),at=`RFC3986`,ot=String,st={RFC1738:e=>String(e).replace(/%20/g,`+`),RFC3986:ot};let ct;const lt=(e,t)=>{let n=ct??Object.hasOwn??Function.prototype.call.bind(Object.prototype.hasOwnProperty);return ct=n,n(e,t)},ut=(()=>{let e=[];for(let t=0;t<256;++t)e.push(`%`+((t<16?`0`:``)+t.toString(16)).toUpperCase());return e})(),dt=1024,ft=(e,t,n,r,i)=>{if(e.length===0)return e;let a=e;if(typeof e==`symbol`?a=Symbol.prototype.toString.call(e):typeof e!=`string`&&(a=String(e)),n===`iso-8859-1`)return escape(a).replace(/%u[0-9a-f]{4}/gi,e=>`%26%23`+Number.parseInt(e.slice(2),16)+`%3B`);let o=``;for(let e=0;e<a.length;){let t=Math.min((Math.floor(e/dt)+1)*dt,a.length);t<a.length&&a.codePointAt(t-1)>65535&&(t+=1);let n=a.length>=dt?a.slice(e,t):a,r=[];for(let e=0;e<n.length;++e){let t=n.charCodeAt(e);if(t===45||t===46||t===95||t===126||t>=48&&t<=57||t>=65&&t<=90||t>=97&&t<=122||i===`RFC1738`&&(t===40||t===41)){r[r.length]=n.charAt(e);continue}if(t<128){r[r.length]=ut[t];continue}if(t<2048){r[r.length]=ut[192|t>>6]+ut[128|t&63];continue}if(t<55296||t>=57344){r[r.length]=ut[224|t>>12]+ut[128|t>>6&63]+ut[128|t&63];continue}e+=1,t=65536+((t&1023)<<10|n.charCodeAt(e)&1023),r[r.length]=ut[240|t>>18]+ut[128|t>>12&63]+ut[128|t>>6&63]+ut[128|t&63]}o+=r.join(``),e=t}return o};function pt(e){return!e||typeof e!=`object`?!1:!!(e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer(e))}function mt(e,t){if(S(e)){let n=[];for(let r of e)n.push(t(r));return n}return t(e)}const ht={brackets(e){return String(e)+`[]`},comma:`comma`,indices(e,t){return String(e)+`[`+t+`]`},repeat(e){return String(e)}},gt=function(e,t){Array.prototype.push.apply(e,S(t)?t:[t])};let _t;const A={addQueryPrefix:!1,allowDots:!1,allowEmptyArrays:!1,arrayFormat:`indices`,charset:`utf-8`,charsetSentinel:!1,delimiter:`&`,encode:!0,encodeDotInKeys:!1,encoder:ft,encodeValuesOnly:!1,format:at,formatter:ot,indices:!1,serializeDate(e){return(_t??=Function.prototype.call.bind(Date.prototype.toISOString))(e)},skipNulls:!1,strictNullHandling:!1};function vt(e){return typeof e==`string`||typeof e==`number`||typeof e==`boolean`||typeof e==`symbol`||typeof e==`bigint`}const yt={};function bt(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h,g,_){let v=e,y=_,b=0,x=!1;for(;(y=y.get(yt))!==void 0&&!x;){let t=y.get(e);if(b+=1,t!==void 0){if(t===b)throw RangeError(`Cyclic object value`);x=!0}y.get(yt)===void 0&&(b=0)}if(typeof l==`function`?v=l(t,v):v instanceof Date?v=f?.(v):n===`comma`&&S(v)&&(v=mt(v,e=>e instanceof Date?f?.(e):e)),v===null){if(a)return c&&!h?c(t,A.encoder,g,`key`,p):t;v=``}if(vt(v)||pt(v)){if(c){let e=h?t:c(t,A.encoder,g,`key`,p);return[m?.(e)+`=`+m?.(c(v,A.encoder,g,`value`,p))]}return[m?.(t)+`=`+m?.(String(v))]}let ee=[];if(v===void 0)return ee;let te;if(n===`comma`&&S(v))h&&c&&(v=mt(v,c)),te=[{value:v.length>0?v.join(`,`)||null:void 0}];else if(S(l))te=l;else{let e=Object.keys(v);u&&e.sort(u),te=e}let ne=s?String(t).replace(/\./g,`%2E`):String(t),re=r&&S(v)&&v.length===1?ne+`[]`:ne;if(i&&S(v)&&v.length===0)return re+`[]`;for(let t of te){let y=typeof t==`object`&&t.value!==void 0?t.value:v[t];if(o&&y===null)continue;let x=d&&s?t.replace(/\./g,`%2E`):t,te;te=S(v)?typeof n==`function`?n(re,x):re:re+(d?`.`+x:`[`+x+`]`),_.set(e,b);let ne=new WeakMap([[yt,_]]);gt(ee,bt(y,te,n,r,i,a,o,s,n===`comma`&&h&&S(v)?null:c,l,u,d,f,p,m,h,g,ne))}return ee}function xt(e=A){if(e.allowEmptyArrays!==void 0&&typeof e.allowEmptyArrays!=`boolean`)throw TypeError("`allowEmptyArrays` option can only be `true` or `false`, when provided");if(e.encodeDotInKeys!==void 0&&typeof e.encodeDotInKeys!=`boolean`)throw TypeError("`encodeDotInKeys` option can only be `true` or `false`, when provided");if(e.encoder!==null&&e.encoder!==void 0&&typeof e.encoder!=`function`)throw TypeError(`Encoder has to be a function.`);let t=e.charset||A.charset;if(e.charset!==void 0&&e.charset!==`utf-8`&&e.charset!==`iso-8859-1`)throw TypeError(`The charset option must be either utf-8, iso-8859-1, or undefined`);let n=at;if(e.format!==void 0){if(!lt(st,e.format))throw TypeError(`Unknown format option provided.`);n=e.format}let r=st[n],i=A.filter;(typeof e.filter==`function`||S(e.filter))&&(i=e.filter);let a;if(a=e.arrayFormat&&e.arrayFormat in ht?e.arrayFormat:`indices`in e?e.indices?`indices`:`repeat`:A.arrayFormat,`commaRoundTrip`in e&&typeof e.commaRoundTrip!=`boolean`)throw TypeError("`commaRoundTrip` must be a boolean, or absent");let o;return o=e.allowDots===void 0?e.encodeDotInKeys?!0:A.allowDots:!!e.allowDots,{addQueryPrefix:typeof e.addQueryPrefix==`boolean`?e.addQueryPrefix:A.addQueryPrefix,allowDots:o,allowEmptyArrays:typeof e.allowEmptyArrays==`boolean`?!!e.allowEmptyArrays:A.allowEmptyArrays,arrayFormat:a,charset:t,charsetSentinel:typeof e.charsetSentinel==`boolean`?e.charsetSentinel:A.charsetSentinel,commaRoundTrip:!!e.commaRoundTrip,delimiter:e.delimiter===void 0?A.delimiter:e.delimiter,encode:typeof e.encode==`boolean`?e.encode:A.encode,encodeDotInKeys:typeof e.encodeDotInKeys==`boolean`?e.encodeDotInKeys:A.encodeDotInKeys,encoder:typeof e.encoder==`function`?e.encoder:A.encoder,encodeValuesOnly:typeof e.encodeValuesOnly==`boolean`?e.encodeValuesOnly:A.encodeValuesOnly,filter:i,format:n,formatter:r,serializeDate:typeof e.serializeDate==`function`?e.serializeDate:A.serializeDate,skipNulls:typeof e.skipNulls==`boolean`?e.skipNulls:A.skipNulls,sort:typeof e.sort==`function`?e.sort:null,strictNullHandling:typeof e.strictNullHandling==`boolean`?e.strictNullHandling:A.strictNullHandling}}function St(e,t={}){let n=e,r=xt(t),i,a;typeof r.filter==`function`?(a=r.filter,n=a(``,n)):S(r.filter)&&(a=r.filter,i=a);let o=[];if(typeof n!=`object`||!n)return``;let s=ht[r.arrayFormat],c=s===`comma`&&r.commaRoundTrip;i||=Object.keys(n),r.sort&&i.sort(r.sort);let l=new WeakMap;for(let e of i)r.skipNulls&&n[e]===null||gt(o,bt(n[e],e,s,c,r.allowEmptyArrays,r.strictNullHandling,r.skipNulls,r.encodeDotInKeys,r.encode?r.encoder:null,r.filter,r.sort,r.allowDots,r.serializeDate,r.format,r.formatter,r.encodeValuesOnly,r.charset,l));let u=o.join(r.delimiter),d=r.addQueryPrefix===!0?`?`:``;return r.charsetSentinel&&(d+=r.charset===`iso-8859-1`?`utf8=%26%2310003%3B&`:`utf8=%E2%9C%93&`),u.length>0?d+u:``}function Ct(e){return St(e,{arrayFormat:`brackets`})}var wt,Tt=class e extends Promise{constructor(e,t,n=Ke){super(e=>{e(null)}),this.responsePromise=t,this.parseResponse=n,wt.set(this,void 0),s(this,wt,e,`f`)}_thenUnwrap(t){return new e(c(this,wt,`f`),this.responsePromise,async(e,n)=>Je(t(await this.parseResponse(e,n),n),n.response))}asResponse(){return this.responsePromise.then(e=>e.response)}async withResponse(){let[e,t]=await Promise.all([this.parse(),this.asResponse()]);return{data:e,response:t,request_id:t.headers.get(`x-request-id`)}}parse(){return this.parsedPromise||=this.responsePromise.then(e=>this.parseResponse(c(this,wt,`f`),e)),this.parsedPromise}then(e,t){return this.parse().then(e,t)}catch(e){return this.parse().catch(e)}finally(e){return this.parse().finally(e)}};wt=new WeakMap;var Et,Dt=class{constructor(e,t,n,r){Et.set(this,void 0),s(this,Et,e,`f`),this.options=r,this.response=t,this.body=n}hasNextPage(){return this.getPaginatedItems().length?this.nextPageRequestOptions()!=null:!1}async getNextPage(){let e=this.nextPageRequestOptions();if(!e)throw new f("No next page expected; please check `.hasNextPage()` before calling `.getNextPage()`.");return await c(this,Et,`f`).requestAPIList(this.constructor,e)}async*iterPages(){let e=this;for(yield e;e.hasNextPage();)e=await e.getNextPage(),yield e}async*[(Et=new WeakMap,Symbol.asyncIterator)](){for await(let e of this.iterPages())for(let t of e.getPaginatedItems())yield t}},Ot=class extends Tt{constructor(e,t,n){super(e,t,async(e,t)=>new n(e,t.response,await Ke(e,t),t.options))}async*[Symbol.asyncIterator](){let e=await this;for await(let t of e)yield t}},kt=class extends Dt{constructor(e,t,n,r){super(e,t,n,r),this.data=n.data||[],this.object=n.object}getPaginatedItems(){return this.data??[]}nextPageRequestOptions(){return null}},j=class extends Dt{constructor(e,t,n,r){super(e,t,n,r),this.data=n.data||[],this.has_more=n.has_more||!1}getPaginatedItems(){return this.data??[]}hasNextPage(){return this.has_more!==!1&&super.hasNextPage()}nextPageRequestOptions(){let e=this.getPaginatedItems(),t=e[e.length-1]?.id;return t?{...this.options,query:{...de(this.options.query),after:t}}:null}},M=class extends Dt{constructor(e,t,n,r){super(e,t,n,r),this.data=n.data||[],this.has_more=n.has_more||!1,this.last_id=n.last_id||``}getPaginatedItems(){return this.data??[]}hasNextPage(){return this.has_more!==!1&&super.hasNextPage()}nextPageRequestOptions(){let e=this.last_id;return e?{...this.options,query:{...de(this.options.query),after:e}}:null}},At=class extends Dt{constructor(e,t,n,r){super(e,t,n,r),this.data=n.data||[],this.has_more=n.has_more||!1,this.next=n.next||null}getPaginatedItems(){return this.data??[]}hasNextPage(){return this.has_more!==!1&&super.hasNextPage()}nextPageRequestOptions(){let e=this.next;return e?{...this.options,query:{...de(this.options.query),after:e}}:null}};const jt={jwt:`urn:ietf:params:oauth:token-type:jwt`,id:`urn:ietf:params:oauth:token-type:id_token`};var Mt=class e{constructor(e,t){this.cachedToken=null,this.refreshPromise=null,this.tokenGeneration=0,this.tokenExchangeUrl=`https://auth.openai.com/oauth/token`,this.config=e,this.fetch=t??_e()}async getToken(){if(!this.cachedToken||e.isTokenExpired(this.cachedToken)){if(this.refreshPromise)return await this.refreshPromise;let e=this.refreshToken(this.tokenGeneration);this.refreshPromise=e;try{return await e}finally{this.refreshPromise===e&&(this.refreshPromise=null)}}if(this.needsRefresh(this.cachedToken)&&!this.refreshPromise){let e=this.refreshToken(this.tokenGeneration).finally(()=>{this.refreshPromise===e&&(this.refreshPromise=null)});this.refreshPromise=e,e.catch(()=>null)}return this.cachedToken.token}async refreshToken(e){let t={grant_type:`urn:ietf:params:oauth:grant-type:token-exchange`,subject_token:await this.config.provider.getToken(),subject_token_type:jt[this.config.provider.tokenType],identity_provider_id:this.config.identityProviderId,service_account_id:this.config.serviceAccountId};this.config.clientId&&(t.client_id=this.config.clientId);let n=await this.fetch(this.tokenExchangeUrl,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t),redirect:`manual`});if(!n.ok){let e=await n.text(),t;try{t=JSON.parse(e)}catch{}throw n.status===400||n.status===401||n.status===403?new oe(n.status,t,n.headers):p.generate(n.status,t,`Token exchange failed with status ${n.status}`,n.headers)}let r=await n.json();if(typeof r!=`object`||!r||!(`access_token`in r)||typeof r.access_token!=`string`||r.access_token.trim().length===0)throw new f(`Token exchange response missing 'access_token' field`);let i=r.access_token,a=r.expires_in??3600;if(typeof a!=`number`||!Number.isFinite(a)||a<=0)throw new f(`Token exchange response has invalid 'expires_in' field`);let o=Date.now(),s=o+a*1e3;if(!Number.isSafeInteger(s)||s<=o)throw new f(`Token exchange response has invalid 'expires_in' field`);return this.tokenGeneration===e&&(this.cachedToken={token:i,expiresAt:s}),i}static isTokenExpired(e){return Date.now()>=e.expiresAt}needsRefresh(e){let t=(this.config.refreshBufferSeconds??1200)*1e3;return Date.now()>=e.expiresAt-t}invalidateToken(){this.tokenGeneration+=1,this.cachedToken=null,this.refreshPromise=null}};const Nt=Symbol(`brand.privateNullableHeaders`),Pt=/^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;function*Ft(e){if(!e)return;if(Nt in e){let{values:t,nulls:n}=e;yield*t.entries();for(let e of n)yield[e,null];return}let t=!1,n;e instanceof Headers?n=e.entries():ue(e)?n=e:(t=!0,n=Object.entries(e??{}));for(let e of n){let n=e[0];if(typeof n!=`string`)throw TypeError(`expected header name to be a string`);let r=ue(e[1])?e[1]:[e[1]],i=!1;for(let e of r)e!==void 0&&(t&&!i&&(i=!0,yield[n,null]),yield[n,e])}}const N=e=>{let t=new Headers,n=new Set;for(let r of e){let e=new Set;for(let[i,a]of Ft(r)){if(!Pt.test(i))throw TypeError(`Header name must be a valid HTTP token ["${i}"]`);let r=i.toLowerCase();e.has(r)||(t.delete(r),e.add(r)),a===null?(t.delete(r),n.add(r)):(t.append(r,a),n.delete(r))}}return{[Nt]:!0,values:t,nulls:n}},It=Symbol(`brand.privateStreamingFile`);function Lt(e,t,n){if(typeof t!=`string`||!t)throw TypeError(`toStreamingFile requires a non-empty file name`);let r=n?.type;return r&&sn(r),{[It]:!0,data:e,name:t,...r?{type:r}:{}}}const Rt=()=>{if(typeof File>`u`){let{process:e}=globalThis,t=typeof e?.versions?.node==`string`&&Number.parseInt(e.versions.node.split(`.`),10)<20;throw Error("`File` is not defined as a global, which is required for file uploads."+(t?" Update to a supported Node.js LTS release, or set `globalThis.File` to `import('node:buffer').File`.":``))}};function zt(e,t,n){return Rt(),new File(e,t??`unknown_file`,n)}function Bt(e,t){if(typeof e!=`object`||!e)return;let n=`name`in e&&e.name&&String(e.name)||`filename`in e&&e.filename&&String(e.filename);if(n)return t?.stripFilename===!1?Ht(n):Vt(n);let r=`url`in e&&e.url&&String(e.url);if(r)try{return Vt(new URL(r).pathname)}catch{return Vt(r)}let i=`path`in e&&e.path&&String(e.path);return i?Vt(i):void 0}function Vt(e){return e.split(/[\\/]/).pop()||void 0}function Ht(e){return e.replace(/\\/g,`/`)}const Ut=e=>typeof e==`object`&&!!e&&typeof e[Symbol.asyncIterator]==`function`,Wt=async(e,t,n)=>$t(e.body)?Qt(e.body)?en(e,n):{...e,body:await qt(e.body,t,n)}:e,P=async(e,t,n)=>Qt(e.body)?en(e,n):{...e,body:await qt(e.body,t,n)},Gt=new WeakMap;function Kt(e){let t=typeof e==`function`?e:e.fetch,n=Gt.get(t);if(n)return n;let r=(async()=>{try{let e;if(`Response`in t)e=t.Response;else{let n=await t(`data:,`);await n.arrayBuffer(),e=n.constructor}let n=new FormData;return n.toString()!==await new e(n).text()}catch{return!0}})();return Gt.set(t,r),r}const qt=async(e,t,n={})=>{if(!await Kt(t))throw TypeError(`The provided fetch function does not support file uploads with the current global FormData class.`);let r=new FormData;return await Promise.all(Object.entries(e||{}).map(([e,t])=>dn(r,e,t,n))),r},Jt=e=>e instanceof Blob&&`name`in e,Yt=e=>typeof e==`object`&&!!e&&`getReader`in e&&typeof e.getReader==`function`,Xt=e=>typeof e==`object`&&!!e&&It in e,Zt=e=>typeof e==`object`&&!!e&&(e instanceof Response||Ut(e)||Yt(e)||Xt(e)||Jt(e)),Qt=e=>{if(Xt(e)||Ut(e)||Yt(e))return!0;if(Array.isArray(e))return e.some(Qt);if(e&&typeof e==`object`&&!Jt(e)&&!(e instanceof Response)){for(let t in e)if(Qt(e[t]))return!0}return!1},$t=e=>{if(Zt(e))return!0;if(Array.isArray(e))return e.some($t);if(e&&typeof e==`object`){for(let t in e)if($t(e[t]))return!0}return!1},en=(e,t={})=>{let n=`openai-${Math.random().toString(36).slice(2)}`,r=ye(tn(e.body,n,t));return{...e,body:r,headers:N([{"content-type":`multipart/form-data; boundary=${n}`},e.headers])}};async function*tn(e,t,n){for await(let{key:r,value:i}of nn(e)){if(Zt(i)){let e=an(i,n),a=on(i);yield w(`--${t}\r\n`),yield w(`Content-Disposition: form-data; name="${un(r)}"; filename="${un(e)}"\r\nContent-Type: ${a}\r\n\r\n`),yield*ln(cn(i))}else yield w(`--${t}\r\n`),yield w(`Content-Disposition: form-data; name="${un(r)}"\r\n\r\n${String(i)}`);yield w(`\r
|
|
6
|
+
`)}yield w(`--${t}--\r\n`)}async function*nn(e){if(!(!e||typeof e!=`object`))for(let[t,n]of Object.entries(e))yield*rn(t,n)}async function*rn(e,t){if(t!==void 0){if(t==null)throw TypeError(`Received null for "${e}"; to pass null in FormData, you must use the string 'null'`);if(typeof t==`string`||typeof t==`number`||typeof t==`boolean`||Zt(t))yield{key:e,value:t};else if(Array.isArray(t))for(let n of t)yield*rn(e+`[]`,n);else if(typeof t==`object`)for(let[n,r]of Object.entries(t))yield*rn(`${e}[${n}]`,r);else throw TypeError(`Invalid value given to form, expected a string, number, boolean, object, Array, File or Blob but got ${t} instead`)}}function an(e,t){if(Xt(e)){let{name:n}=e;if(typeof n!=`string`||!n)throw TypeError(`Streaming upload file name must be a non-empty string`);return t.stripFilenames===!1?Ht(n):n}return Bt(e,{stripFilename:t.stripFilenames})??`unknown_file`}function on(e){let t;return Xt(e)||Jt(e)?{type:t}=e:e instanceof Response&&(t=e.headers.get(`content-type`)??void 0),sn(t||`application/octet-stream`)}function sn(e){if(typeof e!=`string`)throw TypeError(`Streaming upload content type must be a string`);for(let t=0;t<e.length;t+=1){let n=e.codePointAt(t)??0;if(n<=31||n===127)throw TypeError(`Streaming upload content type must not contain control characters`)}return e}function cn(e){return Xt(e)?e.data:e}async function*ln(e){if(typeof e==`string`)yield w(e);else if(ArrayBuffer.isView(e))yield new Uint8Array(e.buffer,e.byteOffset,e.byteLength);else if(e instanceof ArrayBuffer)yield new Uint8Array(e);else if(e instanceof Response)yield*ln(e.body||await e.blob());else if(e instanceof Blob)typeof e.stream==`function`?yield*ln(e.stream()):yield new Uint8Array(await e.arrayBuffer());else if(Yt(e))for await(let t of be(e))yield*ln(t);else if(Ut(e))for await(let t of e)yield*ln(t);else throw TypeError(`Invalid streaming file chunk: ${String(e)}`)}function un(e){return Array.from(e,e=>{let t=e.codePointAt(0)??0;return t<=31||t===127||e===`"`||e===`\\`?encodeURIComponent(e):e}).join(``)}const dn=async(e,t,n,r)=>{if(n!==void 0){if(n==null)throw TypeError(`Received null for "${t}"; to pass null in FormData, you must use the string 'null'`);if(typeof n==`string`||typeof n==`number`||typeof n==`boolean`)e.append(t,String(n));else if(n instanceof Response)e.append(t,zt([await n.blob()],Bt(n,{stripFilename:r.stripFilenames})));else if(Ut(n))e.append(t,zt([await new Response(ye(n)).blob()],Bt(n,{stripFilename:r.stripFilenames})));else if(Jt(n))e.append(t,n,Bt(n,{stripFilename:r.stripFilenames}));else if(Array.isArray(n))await Promise.all(n.map(n=>dn(e,t+`[]`,n,r)));else if(typeof n==`object`)await Promise.all(Object.entries(n).map(([n,i])=>dn(e,`${t}[${n}]`,i,r)));else throw TypeError(`Invalid value given to form, expected a string, number, boolean, object, Array, File or Blob but got ${n} instead`)}},fn=e=>typeof e==`object`&&!!e&&typeof e.size==`number`&&typeof e.type==`string`&&typeof e.text==`function`&&typeof e.slice==`function`&&typeof e.arrayBuffer==`function`,pn=e=>typeof e==`object`&&!!e&&typeof e.name==`string`&&typeof e.lastModified==`number`&&fn(e),mn=e=>typeof e==`object`&&!!e&&typeof e.url==`string`&&typeof e.blob==`function`,hn=(e,t)=>t?.type!=null&&t.type!==e.type||t?.lastModified!=null&&t.lastModified!==e.lastModified||t?.endings!=null,gn=(e,t,n)=>(t==null||t===e.name)&&!hn(e,n);async function _n(e,t,n){if(Rt(),e=await e,pn(e)){let r={...n,type:n?.type??e.type,lastModified:n?.lastModified??e.lastModified};return e instanceof File?gn(e,t,n)?e:zt([e],t??e.name,r):zt([await e.arrayBuffer()],t??e.name,r)}if(mn(e)){let r=await e.blob();t||=Bt(e);let i=n?.type===void 0&&r.type?{...n,type:r.type}:n;return zt(await vn(r),t,i)}let r=await vn(e);if(t||=Bt(e),n?.type===void 0){let e=r.find(e=>typeof e==`object`&&`type`in e&&!!e.type);e&&(n={...n,type:e.type})}return zt(r,t,n)}async function vn(e){let t=[];if(typeof e==`string`||ArrayBuffer.isView(e)||e instanceof ArrayBuffer)t.push(e);else if(fn(e))t.push(e instanceof Blob?e:new Blob([await e.arrayBuffer()],{type:e.type}));else if(Ut(e))for await(let n of e)t.push(...await vn(n));else{let t=e?.constructor?.name;throw Error(`Unexpected data type: ${typeof e}${t?`; constructor: ${t}`:``}${yn(e)}`)}return t}function yn(e){return typeof e!=`object`||!e?``:`; props: [${Object.getOwnPropertyNames(e).map(e=>`"${e}"`).join(`, `)}]`}var F=class{constructor(e){this._client=e}};function bn(e){return e.replace(/[^A-Za-z0-9\-._~!$&'()*+,;=:@]+/g,encodeURIComponent)}const xn=Object.freeze(Object.create(null)),I=((e=bn)=>function(t,...n){if(t.length===1)return t[0];let r=!1,i=[],a=``;for(let o=0;o<t.length;o+=1)if(o in t){let s=t[o];/[?#]/.test(s)&&(r=!0);let c=n[o],l=(r?encodeURIComponent:e)(``+c);o!==n.length&&(c==null||typeof c==`object`&&c.toString===Object.getPrototypeOf(Object.getPrototypeOf(c.hasOwnProperty??xn)??xn)?.toString)&&(l=c+``,i.push({start:a.length+s.length,length:l.length,error:`Value of type ${Object.prototype.toString.call(c).slice(8,-1)} is not a valid path parameter`})),a+=s+(o===n.length?``:l)}let o=a.split(/[?#]/,1)[0],s=/(?<=^|\/)(?:\.|%2e){1,2}(?=\/|$)/gi,c;for(;(c=s.exec(o))!==null;)i.push({start:c.index,length:c[0].length,error:`Value "${c[0]}" can't be safely passed as a path parameter`});if(i.sort((e,t)=>e.start-t.start),i.length>0){let e=0,t=``;for(let n of i){let r=` `.repeat(n.start-e),i=`^`.repeat(n.length);e=n.start+n.length,t+=r+i}throw new f(`Path parameters result in path with invalid segments:\n${i.map(e=>e.error).join(`
|
|
7
|
+
`)}\n${a}\n${t}`)}return a})(bn);var Sn=class extends F{list(e,t={},n){return this._client.getAPIList(I`/chat/completions/${e}/messages`,j,{query:t,...n,__security:{bearerAuth:!0}})}};function Cn(e){return e!==void 0&&`function`in e&&e.function!==void 0}function wn(e){return e?.$brand===`auto-parseable-response-format`}function Tn(e){return wn(e)||e?.type===`json_schema`}function En(e,t){return Tn(e)?typeof e==`object`&&e&&`$parseRaw`in e&&typeof e.$parseRaw==`function`?e.$parseRaw(t):JSON.parse(t):null}function Dn(e){return e?.$brand===`auto-parseable-tool`}function On(e,t){return!t||!Nn(t)?{...e,choices:e.choices.map(e=>({...e,message:{...e.message,parsed:null,...e.message.tool_calls?{tool_calls:e.message.tool_calls}:void 0}}))}:kn(e,t)}function kn(e,t){let n=e.choices.map(e=>{if(e.finish_reason===`length`)throw new re;if(e.finish_reason===`content_filter`)throw new ie;return{...e,message:{...e.message,...e.message.tool_calls?{tool_calls:e.message.tool_calls?.map(e=>jn(t,e))??void 0}:void 0,parsed:e.message.content!==null&&e.message.content!==void 0&&!e.message.refusal&&(e.message.content!==``||!e.message.tool_calls?.length&&!e.message.function_call)?An(t,e.message.content):null}}});return{...e,choices:n}}function An(e,t){return En(e.response_format,t)}function jn(e,t){if(t.type===`custom`)return t;if(t.type!==`function`){let e=t.type;throw new f(`Currently only \`function\` and \`custom\` tool calls are supported; Received \`${e}\``)}let n=e.tools?.find(e=>Cn(e)&&e.function?.name===t.function.name),r=null;return Dn(n)?r=n.$parseRaw(t.function.arguments):n?.function.strict&&(r=JSON.parse(t.function.arguments)),{...t,function:{...t.function,parsed_arguments:r}}}function Mn(e,t){if(!e||!(`tools`in e)||!e.tools||t.type!==`function`)return!1;let n=e.tools?.find(e=>Cn(e)&&e.function?.name===t.function?.name);return Cn(n)&&(Dn(n)||n?.function.strict||!1)}function Nn(e){return Tn(e.response_format)?!0:e.tools?.some(e=>Dn(e)||e.type===`function`&&e.function.strict===!0)??!1}function Pn(e){for(let t of e??[])if(t.type!==`custom`){if(t.type!==`function`){let e=t.type;throw new f(`Currently only \`function\` and \`custom\` tool types are supported; Received \`${e}\``)}if(t.function.strict!==!0)throw new f(`The \`${t.function.name}\` tool is not marked with \`strict: true\`. Only strict function tools can be auto-parsed`)}}const Fn=e=>e?.role===`assistant`,In=e=>e?.role===`tool`;var Ln,Rn,zn,Bn,Vn,Hn,Un,Wn,Gn,Kn,qn,Jn,Yn,Xn,Zn;function Qn(){let e=[],t=0;return{get length(){return e.length-t},enqueue(t){e.push(t)},dequeue(){if(t===e.length)return;let n=e[t];return e[t]=void 0,t+=1,t===e.length?(e=[],t=0):t>=1024&&t*2>=e.length&&(e=e.slice(t),t=0),n},clear(){e=[],t=0}}}var $n=class{constructor(){Ln.add(this),this.controller=new AbortController,Rn.set(this,void 0),zn.set(this,()=>void 0),Bn.set(this,()=>void 0),Vn.set(this,void 0),Hn.set(this,()=>void 0),Un.set(this,()=>void 0),Wn.set(this,Object.create(null)),Gn.set(this,[]),Kn.set(this,!1),qn.set(this,!1),Jn.set(this,!1),Yn.set(this,!1),s(this,Rn,new Promise((e,t)=>{s(this,zn,e,`f`),s(this,Bn,t,`f`)}),`f`),s(this,Vn,new Promise((e,t)=>{s(this,Hn,e,`f`),s(this,Un,t,`f`)}),`f`),c(this,Rn,`f`).catch(()=>void 0),c(this,Vn,`f`).catch(()=>void 0)}_run(e){setTimeout(()=>{let t=!1;Promise.resolve().then(e).catch(e=>{t=!0,c(this,Ln,`m`,Zn).call(this,e)}).then(()=>{if(!t){try{this._emitFinal()}catch(e){c(this,Ln,`m`,Zn).call(this,e);return}this._emit(`end`)}})},0)}_connected(){this.ended||(c(this,zn,`f`).call(this),this._emit(`connect`))}get ended(){return c(this,Kn,`f`)}get errored(){return c(this,qn,`f`)}get aborted(){return c(this,Jn,`f`)}abort(){this.controller.abort()}_listenForAbort(e){if(!e||this.ended)return;if(e.aborted){this.controller.abort();return}let t=()=>this.controller.abort();e.addEventListener(`abort`,t,{once:!0}),c(this,Gn,`f`).push({signal:e,listener:t})}on(e,t){var n;return((n=c(this,Wn,`f`))[e]||(n[e]=[])).push({listener:t}),this}off(e,t){let n=c(this,Wn,`f`)[e];if(!n)return this;let r=n.findIndex(e=>e.listener===t);return r!==-1&&n.splice(r,1),this}once(e,t){var n;return((n=c(this,Wn,`f`))[e]||(n[e]=[])).push({listener:t,once:!0}),this}emitted(e){return new Promise((t,n)=>{s(this,Yn,!0,`f`);let r=t=>{this.off(e,i),n(t)},i=(...n)=>{e!==`error`&&this.off(`error`,r),t(n.length>1?n:n[0])};e!==`error`&&this.once(`error`,r),this.once(e,i)})}events(e){return this._createIterator(t=>{let n=(...e)=>t(e);return this.on(e,n),()=>this.off(e,n)},{rejectOnError:e!==`error`,rejectOnAbort:e!==`abort`})}_createIterator(e,{rejectOnError:t=!0,rejectOnAbort:n=!0,onReturn:r}={}){let i=Qn(),a=Qn(),o=this.ended,s,c=!1,l=()=>void 0,u=()=>({value:void 0,done:!0}),d=()=>{for(;a.length;)a.dequeue().resolve(u())},f=()=>{!s||c||!a.length||(c=!0,a.dequeue().reject(s))},p=()=>{l(),this.off(`end`,g),t&&this.off(`error`,h),n&&this.off(`abort`,h)},m=e=>{if(o)return;let t=a.dequeue();t?t.resolve({value:e,done:!1}):i.enqueue(e)},h=e=>{s=e,i.length||f()},g=()=>{o=!0,p(),i.length||(f(),d())};return o||(l=e(m),this.on(`end`,g),t&&this.on(`error`,h),n&&this.on(`abort`,h)),{next:()=>i.length?Promise.resolve({value:i.dequeue(),done:!1}):s&&!c?(c=!0,Promise.reject(s)):o?Promise.resolve(u()):new Promise((e,t)=>{a.enqueue({resolve:e,reject:t})}),return:()=>(o=!0,i.clear(),p(),d(),r&&(this.done().catch(()=>void 0),r()),Promise.resolve(u())),[Symbol.asyncIterator](){return this}}}async done(){s(this,Yn,!0,`f`),await c(this,Vn,`f`)}_hasListeners(e){return!!c(this,Wn,`f`)[e]?.length}_emit(e,...t){if(c(this,Kn,`f`))return;e===`end`&&(c(this,Ln,`m`,Xn).call(this),s(this,Kn,!0,`f`),c(this,Hn,`f`).call(this));let n=c(this,Wn,`f`)[e];if(n){c(this,Wn,`f`)[e]=n.filter(e=>!e.once);for(let{listener:e}of n)e(...t)}if(e===`abort`){let e=t[0];!c(this,Yn,`f`)&&!n?.length&&Promise.reject(e),c(this,Bn,`f`).call(this,e),c(this,Un,`f`).call(this,e),this._emit(`end`);return}if(e===`error`){let e=t[0];!c(this,Yn,`f`)&&!n?.length&&Promise.reject(e),c(this,Bn,`f`).call(this,e),c(this,Un,`f`).call(this,e),this._emit(`end`)}}_emitFinal(){}};Rn=new WeakMap,zn=new WeakMap,Bn=new WeakMap,Vn=new WeakMap,Hn=new WeakMap,Un=new WeakMap,Wn=new WeakMap,Gn=new WeakMap,Kn=new WeakMap,qn=new WeakMap,Jn=new WeakMap,Yn=new WeakMap,Ln=new WeakSet,Xn=function(){for(let{signal:e,listener:t}of c(this,Gn,`f`).splice(0))e.removeEventListener(`abort`,t)},Zn=function(e){if(s(this,qn,!0,`f`),e instanceof Error&&e.name===`AbortError`&&(e=new m),e instanceof m)return s(this,Jn,!0,`f`),this._emit(`abort`,e);if(e instanceof f)return this._emit(`error`,e);if(e instanceof Error){let t=new f(e.message);return t.cause=e,this._emit(`error`,t)}return this._emit(`error`,new f(String(e)))};function er(e){return typeof e.parse==`function`}var L,tr,nr,rr,ir,ar,or,sr,cr;function lr(e){for(let t of e.choices)for(let e of t.message.tool_calls??[])e.id||=`call_${l()}`}function ur(e){if(!Fn(e))return e;let t={role:`assistant`};return e.audio!=null&&(t.audio={id:e.audio.id}),e.content!==void 0&&(t.content=e.content),e.function_call!=null&&(t.function_call=e.function_call),e.name!==void 0&&(t.name=e.name),e.refusal!=null&&(t.refusal=e.refusal),e.tool_calls!==void 0&&(t.tool_calls=e.tool_calls.map(e=>e.type===`custom`?{id:e.id,type:e.type,custom:{input:e.custom.input,name:e.custom.name}}:{id:e.id,type:e.type,function:{arguments:e.function.arguments,name:e.function.name}})),t}var dr=class extends $n{constructor(){super(...arguments),L.add(this),this._chatCompletions=[],this.messages=[]}_addChatCompletion(e){lr(e),this._chatCompletions.push(e),this._emit(`chatCompletion`,e);let t=e.choices[0]?.message;return t&&this._addMessage(t),e}_addMessage(e,t=!0){if(`content`in e||(e.content=null),this.messages.push(e),t){if(this._emit(`message`,e),In(e)&&e.content)this._emit(`functionToolCallResult`,e.content);else if(Fn(e)&&e.tool_calls)for(let t of e.tool_calls)t.type===`function`&&this._emit(`functionToolCall`,t.function)}}async finalChatCompletion(){await this.done();let e=this._chatCompletions[this._chatCompletions.length-1];if(!e)throw new f(`stream ended without producing a ChatCompletion`);return e}async finalContent(){return await this.done(),c(this,L,`m`,nr).call(this)}async finalMessage(){return await this.done(),c(this,L,`m`,rr).call(this)}async finalFunctionToolCall(){return await this.done(),c(this,L,`m`,ir).call(this)}async finalFunctionToolCallResult(){return await this.done(),c(this,L,`m`,ar).call(this)}async totalUsage(){return await this.done(),c(this,L,`m`,or).call(this)}allChatCompletions(){return[...this._chatCompletions]}_emitFinal(){let e=this._chatCompletions[this._chatCompletions.length-1];e&&this._emit(`finalChatCompletion`,e);let t=c(this,L,`m`,rr).call(this);t&&this._emit(`finalMessage`,t);let n=c(this,L,`m`,nr).call(this);n&&this._emit(`finalContent`,n);let r=c(this,L,`m`,ir).call(this);r&&this._emit(`finalFunctionToolCall`,r);let i=c(this,L,`m`,ar).call(this);i!=null&&this._emit(`finalFunctionToolCallResult`,i),this._chatCompletions.some(e=>e.usage)&&this._emit(`totalUsage`,c(this,L,`m`,or).call(this))}async _createChatCompletion(e,t,n){this._listenForAbort(n?.signal),c(tr,tr,`m`,sr).call(tr,t);let r=await e.chat.completions.create({...t,stream:!1},{...n,signal:this.controller.signal});return this._connected(),this._addChatCompletion(kn(r,t))}async _runChatCompletion(e,t,n){for(let e of t.messages)this._addMessage(e,!1);return await this._createChatCompletion(e,t,n)}async _runTools(e,t,n,r){let i=`tool`,{tool_choice:a=`auto`,stream:o,toolContext:s,...l}=t,u=s,d=typeof a!=`string`&&a.type===`function`&&a?.function?.name,{maxChatCompletions:p=10,afterCompletion:m}=r||{},h=t.tools.map(e=>{if(Dn(e)){if(!e.$callback)throw new f("Tool given to `.runTools()` that does not have an associated function");return{type:`function`,function:{function:e.$callback,name:e.function.name,description:e.function.description||``,parameters:e.function.parameters,parse:e.$parseRaw,strict:!0}}}return e}),g=Object.create(null);for(let e of h)e.type===`function`&&(g[e.function.name||e.function.function.name]=e.function);let _=`tools`in t?h.map(e=>e.type===`function`?{type:`function`,function:{name:e.function.name||e.function.function.name,parameters:e.function.parameters,description:e.function.description,strict:e.function.strict}}:e):void 0;for(let e of t.messages)this._addMessage(e,!1);let v=async e=>{if(e.type!==`function`)return{message:void 0,functionCalled:!1};let t=e.id,{name:r,arguments:a}=e.function,o=g[r];if(!o){let e=`Invalid tool_call: ${JSON.stringify(r)}. Available options are: ${Object.keys(g).map(e=>JSON.stringify(e)).join(`, `)}. Please try again`;return{message:{role:i,tool_call_id:t,content:e},functionCalled:!1}}if(d&&d!==r){let e=`Invalid tool_call: ${JSON.stringify(r)}. ${JSON.stringify(d)} requested. Please try again`;return{message:{role:i,tool_call_id:t,content:e},functionCalled:!1}}let s;if(er(o)){let e;try{e=await o.parse(a)}catch(e){let n=e instanceof Error?e.message:String(e);return{message:{role:i,tool_call_id:t,content:n},functionCalled:!1}}s=await o.function(e,n,u)}else s=await o.function(a,n,u);let l=c(tr,tr,`m`,cr).call(tr,s);return{message:{role:i,tool_call_id:t,content:l},functionCalled:!0}};for(let i=0;i<p;++i){let i=await this._createChatCompletion(e,{...l,tool_choice:a,tools:_,messages:this.messages.map(ur)},r),o=i.choices[0]?.message;if(!o)throw new f(`missing message in ChatCompletion response`);if(!o.tool_calls?.length){await m?.(i,n);return}if(d||t.parallel_tool_calls===!1)for(let e of o.tool_calls){let t=await v(e);if(t.message&&this._addMessage(t.message),d&&t.functionCalled){await m?.(i,n);return}}else{let e=await Promise.allSettled(o.tool_calls.map(v));for(let t of e)if(t.status===`rejected`)throw t.reason;for(let t of e)t.status===`fulfilled`&&t.value.message&&this._addMessage(t.value.message)}await m?.(i,n)}}};tr=dr,L=new WeakSet,nr=function(){return c(this,L,`m`,rr).call(this).content??null},rr=function(){let e=this.messages.length;for(;e-->0;){let t=this.messages[e];if(Fn(t))return{...t,content:t.content??null,refusal:t.refusal??null}}throw new f(`stream ended without producing a ChatCompletionMessage with role=assistant`)},ir=function(){for(let e=this.messages.length-1;e>=0;e--){let t=this.messages[e];if(Fn(t)&&t?.tool_calls?.length)for(let e=t.tool_calls.length-1;e>=0;e--){let n=t.tool_calls[e];if(n?.type===`function`)return n.function}}},ar=function(){for(let e=this.messages.length-1;e>=0;e--){let t=this.messages[e];if(In(t)&&t.content!=null&&typeof t.content==`string`&&this.messages.some(e=>e.role===`assistant`&&e.tool_calls?.some(e=>e.type===`function`&&e.id===t.tool_call_id)))return t.content}},or=function(){let e={completion_tokens:0,prompt_tokens:0,total_tokens:0};for(let{usage:t}of this._chatCompletions)t&&(e.completion_tokens+=t.completion_tokens,e.prompt_tokens+=t.prompt_tokens,e.total_tokens+=t.total_tokens);return e},sr=function(e){if(e.n!=null&&e.n>1)throw new f(`ChatCompletion convenience helpers only support n=1 at this time. To use n>1, please use chat.completions.create() directly.`)},cr=function(e){return typeof e==`string`?e:e===void 0?`undefined`:JSON.stringify(e)};var fr=class e extends dr{static runTools(t,n,r){let i=new e,a={...r,__metadata:{...r?.__metadata,helperMethod:`runTools`}};return i._run(()=>i._runTools(t,n,i,a)),i}_addMessage(e,t=!0){super._addMessage(e,t),Fn(e)&&e.content&&this._emit(`content`,e.content)}};const R={STR:1,NUM:2,ARR:4,OBJ:8,NULL:16,BOOL:32,NAN:64,INFINITY:128,MINUS_INFINITY:256,INF:384,SPECIAL:496,ATOM:499,COLLECTION:12,ALL:511};var pr=class extends Error{},mr=class extends Error{};function hr(e,t=R.ALL){if(typeof e!=`string`)throw TypeError(`expecting str, got ${typeof e}`);if(!e.trim())throw Error(`${e} is empty`);return gr(e.trim(),t)}const gr=(e,t)=>{let n=e.length,r=0,i=e=>{throw new pr(`${e} at position ${r}`)},a=e=>{throw new mr(`${e} at position ${r}`)},o=()=>(d(),r>=n&&i(`Unexpected end of input`),e[r]===`"`?s():e[r]===`{`?c():e[r]===`[`?l():e.substring(r,r+4)===`null`||R.NULL&t&&n-r<4&&`null`.startsWith(e.substring(r))?(r+=4,null):e.substring(r,r+4)===`true`||R.BOOL&t&&n-r<4&&`true`.startsWith(e.substring(r))?(r+=4,!0):e.substring(r,r+5)===`false`||R.BOOL&t&&n-r<5&&`false`.startsWith(e.substring(r))?(r+=5,!1):e.substring(r,r+8)===`Infinity`||R.INFINITY&t&&n-r<8&&`Infinity`.startsWith(e.substring(r))?(r+=8,1/0):e.substring(r,r+9)===`-Infinity`||R.MINUS_INFINITY&t&&n-r>1&&n-r<9&&`-Infinity`.startsWith(e.substring(r))?(r+=9,-1/0):e.substring(r,r+3)===`NaN`||R.NAN&t&&n-r<3&&`NaN`.startsWith(e.substring(r))?(r+=3,NaN):u()),s=()=>{let o=r,s=!1;for(r++;r<n&&(e[r]!==`"`||s&&e[r-1]===`\\`);)s=e[r]===`\\`&&!s,r++;if(e.charAt(r)===`"`)try{return JSON.parse(e.substring(o,++r-Number(s)))}catch(e){a(String(e))}else if(R.STR&t)try{return JSON.parse(e.substring(o,r-Number(s))+`"`)}catch{return JSON.parse(e.substring(o,e.lastIndexOf(`\\`))+`"`)}i(`Unterminated string literal`)},c=()=>{r++,d();let a={};try{for(;e[r]!==`}`;){if(d(),r>=n&&R.OBJ&t)return a;let i=s();d(),r++;try{let e=o();Object.defineProperty(a,i,{value:e,writable:!0,enumerable:!0,configurable:!0})}catch(e){if(R.OBJ&t)return a;throw e}d(),e[r]===`,`&&r++}}catch{if(R.OBJ&t)return a;i(`Expected '}' at end of object`)}return r++,a},l=()=>{r++;let n=[];try{for(;e[r]!==`]`;)n.push(o()),d(),e[r]===`,`&&r++}catch{if(R.ARR&t)return n;i(`Expected ']' at end of array`)}return r++,n},u=()=>{if(r===0){e===`-`&&R.NUM&t&&i(`Not sure what '-' is`);try{return JSON.parse(e)}catch(n){if(R.NUM&t)try{return e[e.length-1]===`.`?JSON.parse(e.substring(0,e.lastIndexOf(`.`))):JSON.parse(e.substring(0,e.lastIndexOf(`e`)))}catch{}a(String(n))}}let o=r;for(e[r]===`-`&&r++;e[r]&&!`,]}`.includes(e[r]);)r++;r===n&&!(R.NUM&t)&&i(`Unterminated number literal`);try{return JSON.parse(e.substring(o,r))}catch{e.substring(o,r)===`-`&&R.NUM&t&&i(`Not sure what '-' is`);try{return JSON.parse(e.substring(o,e.lastIndexOf(`e`)))}catch(e){a(String(e))}}},d=()=>{for(;r<n&&`
|
|
8
|
+
\r `.includes(e[r]);)r++};return o()},_r=e=>hr(e,R.ALL^R.NUM);var z,B,vr,yr,V,br,xr,Sr,Cr,wr,Tr,Er;const Dr=`chat.completion.chunk.message:`;function Or(e,t,n){let r={type:`message`,message:t,...n?{tool_call_ids:n}:{}};return{id:e.id,choices:[],created:e.created,model:e.model,object:`${Dr}${JSON.stringify(r)}`}}function kr(e){return`type`in e&&e.type===`message`&&`message`in e||`object`in e&&typeof e.object==`string`&&e.object.startsWith(Dr)}function Ar(e){return`type`in e?e:JSON.parse(e.object.slice(30))}function jr(e,t){return Object.prototype.propertyIsEnumerable.call(t,`__proto__`)&&!pe(e,`__proto__`)&&Object.defineProperty(e,"__proto__",{value:void 0,writable:!0,enumerable:!0,configurable:!0}),Object.assign(e,t)}var Mr=class e extends dr{constructor(e){super(),z.add(this),B.set(this,void 0),vr.set(this,void 0),yr.set(this,void 0),V.set(this,void 0),s(this,B,e,`f`),s(this,vr,new Set,`f`),s(this,yr,[],`f`)}get currentChatCompletionSnapshot(){return c(this,V,`f`)}static fromReadableStream(t){let n=new e(null);return n._run(()=>n._fromReadableStream(t)),n}static createChatCompletion(t,n,r){let i=new e(n);return i._run(()=>i._runChatCompletion(t,{...n,stream:!0},{...r,__metadata:{...r?.__metadata,helperMethod:`stream`}})),i}async _createChatCompletion(e,t,n){this._listenForAbort(n?.signal),c(this,z,`m`,br).call(this);let r=await e.chat.completions.create({...t,stream:!0},{...n,signal:this.controller.signal});this._connected();for await(let e of r)c(this,z,`m`,Sr).call(this,e);if(r.controller.signal?.aborted)throw new m;return this._addChatCompletion(c(this,z,`m`,Tr).call(this))}async _fromReadableStream(e,t){this._listenForAbort(t?.signal),c(this,z,`m`,br).call(this),this._connected();let n=Ve.fromReadableStream(e,this.controller),r;for await(let e of n){if(kr(e)){let t=Ar(e);if(c(this,V,`f`)){let e=c(this,V,`f`).choices[0]?.message.tool_calls;for(let[n,r]of t.tool_call_ids?.entries()??[]){let t=e?.[n];t&&r&&(t.id=r)}this._addChatCompletion(c(this,z,`m`,Tr).call(this)),r=void 0}this._addMessage(t.message);continue}let t=e;r&&t.id&&r!==t.id&&this._addChatCompletion(c(this,z,`m`,Tr).call(this)),c(this,z,`m`,Sr).call(this,t),t.id&&(r=t.id)}if(n.controller.signal?.aborted)throw new m;if(c(this,V,`f`))return this._addChatCompletion(c(this,z,`m`,Tr).call(this));let i=this._chatCompletions[this._chatCompletions.length-1];if(i)return i;throw new f(`request ended without sending any chunks`)}[(B=new WeakMap,vr=new WeakMap,yr=new WeakMap,V=new WeakMap,z=new WeakSet,br=function(){this.ended||(s(this,vr,new Set,`f`),s(this,V,void 0,`f`))},xr=function(e){let t=c(this,yr,`f`)[e.index];return t||(t={content_done:!1,refusal_done:!1,logprobs_content_done:!1,logprobs_refusal_done:!1,done_tool_calls:new Set,current_tool_call_index:null},c(this,yr,`f`)[e.index]=t,t)},Sr=function(e){if(this.ended)return;let t=c(this,z,`m`,Er).call(this,e);this._emit(`chunk`,e,t);for(let n of e.choices){let e=t.choices[n.index],{delta:r}=n;r?.content!=null&&e.message?.role===`assistant`&&e.message?.content&&(this._emit(`content`,r.content,e.message.content),this._emit(`content.delta`,{delta:r.content,snapshot:e.message.content,parsed:e.message.parsed})),r?.refusal!=null&&e.message?.role===`assistant`&&e.message?.refusal&&this._emit(`refusal.delta`,{delta:r.refusal,snapshot:e.message.refusal}),n.logprobs?.content!=null&&e.message?.role===`assistant`&&this._emit(`logprobs.content.delta`,{content:n.logprobs?.content,snapshot:e.logprobs?.content??[]}),n.logprobs?.refusal!=null&&e.message?.role===`assistant`&&this._emit(`logprobs.refusal.delta`,{refusal:n.logprobs?.refusal,snapshot:e.logprobs?.refusal??[]});let i=c(this,z,`m`,xr).call(this,e);e.finish_reason&&(c(this,z,`m`,wr).call(this,e),i.current_tool_call_index!=null&&c(this,z,`m`,Cr).call(this,e,i.current_tool_call_index));for(let t of r?.tool_calls??[])i.current_tool_call_index!==t.index&&(c(this,z,`m`,wr).call(this,e),i.current_tool_call_index!=null&&c(this,z,`m`,Cr).call(this,e,i.current_tool_call_index)),i.current_tool_call_index=t.index;for(let t of r?.tool_calls??[]){let n=e.message.tool_calls?.[t.index];n?.type&&(n.type===`function`?this._emit(`tool_calls.function.arguments.delta`,{name:n.function.name,index:t.index,arguments:n.function.arguments,parsed_arguments:n.function.parsed_arguments,arguments_delta:t.function?.arguments??``}):n.type)}}},Cr=function(e,t){if(c(this,z,`m`,xr).call(this,e).done_tool_calls.has(t))return;let n=e.message.tool_calls?.[t];if(!n)throw Error(`no tool call snapshot`);if(!n.type)throw Error("tool call snapshot missing `type`");if(n.type===`function`){let e=c(this,B,`f`)?.tools?.find(e=>Cn(e)&&e.function.name===n.function.name),r=null;Dn(e)?r=e.$parseRaw(n.function.arguments):e?.function.strict&&(r=JSON.parse(n.function.arguments)),this._emit(`tool_calls.function.arguments.done`,{name:n.function.name,index:t,arguments:n.function.arguments,parsed_arguments:r})}else n.type},wr=function(e){let t=c(this,z,`m`,xr).call(this,e);e.message.content!=null&&(e.message.content!==``||!e.message.refusal&&!e.message.tool_calls?.length&&!e.message.function_call)&&!t.content_done&&(t.content_done=!0,this._emit(`content.done`,{content:e.message.content,parsed:e.message.refusal?null:En(c(this,B,`f`)?.response_format,e.message.content)})),e.message.refusal&&!t.refusal_done&&(t.refusal_done=!0,this._emit(`refusal.done`,{refusal:e.message.refusal})),e.logprobs?.content&&!t.logprobs_content_done&&(t.logprobs_content_done=!0,this._emit(`logprobs.content.done`,{content:e.logprobs.content})),e.logprobs?.refusal&&!t.logprobs_refusal_done&&(t.logprobs_refusal_done=!0,this._emit(`logprobs.refusal.done`,{refusal:e.logprobs.refusal}))},Tr=function(){if(this.ended)throw new f(`stream has ended, this shouldn't happen`);let e=c(this,V,`f`);if(!e)throw new f(`request ended without sending any chunks`);let t=c(this,vr,`f`);return s(this,vr,new Set,`f`),s(this,V,void 0,`f`),s(this,yr,[],`f`),Nr(e,c(this,B,`f`),t)},Er=function(e){var t,n,r,i,a;let o=c(this,V,`f`),{choices:l,...u}=e;if(o)e.id&&jr(o,u);else{let e={...u,choices:[]};s(this,V,e,`f`),o=e}let d=c(this,B,`f`)?.n,p=typeof d==`number`&&Number.isSafeInteger(d)&&d>0?Math.min(d,128):128;for(let{delta:s,finish_reason:l,index:u,logprobs:d=null,...m}of e.choices){if(!Number.isSafeInteger(u)||u<0||u>=p)throw new f(`Chat completion stream contains an invalid choice index: ${u}`);let e=o.choices[u];if(!e){let t={finish_reason:l,index:u,message:{},logprobs:d,...m};o.choices[u]=t,e=t}if(d){if(e.logprobs){let{content:r,refusal:i,...a}=d;jr(e.logprobs,a),r&&((t=e.logprobs).content??(t.content=[]),e.logprobs.content.push(...r)),i&&((n=e.logprobs).refusal??(n.refusal=[]),e.logprobs.refusal.push(...i))}else e.logprobs={...d}}if(l&&(e.finish_reason=l,c(this,B,`f`)&&Nn(c(this,B,`f`)))){if(l===`length`)throw new re;if(l===`content_filter`)throw new ie}if(jr(e,m),!s)continue;c(this,vr,`f`).delete(u);let{audio:h,content:g,refusal:_,function_call:v,role:y,tool_calls:b,...x}=s;if(jr(e.message,x),h?.expires_at!=null&&h.id==null&&h.data==null&&h.transcript==null&&g==null&&_==null&&v==null&&y==null&&b==null&&Object.keys(x).length===0&&c(this,vr,`f`).add(u),_&&(e.message.refusal=(e.message.refusal||``)+_),y&&(e.message.role=y),h){let t=(r=e.message).audio??(r.audio={});h.id!=null&&(t.id=h.id),h.data!=null&&(t.data=(t.data??``)+h.data),h.transcript!=null&&(t.transcript=(t.transcript??``)+h.transcript),h.expires_at!=null&&(t.expires_at=h.expires_at)}if(v&&(e.message.function_call?(v.name&&(e.message.function_call.name=v.name),v.arguments&&((i=e.message.function_call).arguments??(i.arguments=``),e.message.function_call.arguments+=v.arguments)):e.message.function_call=v),g!=null&&(e.message.content=(e.message.content||``)+g,!e.message.refusal&&Tn(c(this,B,`f`)?.response_format)&&(e.message.parsed=e.message.content.trim()?_r(e.message.content):null)),b){let t=(a=e.message).tool_calls??(a.tool_calls=[]);for(let{index:e,id:n,type:r,function:i,custom:a,...o}of b){if(!Number.isSafeInteger(e)||e<0||e>=128)throw new f(`Chat completion stream contains an invalid tool call index: ${e}`);let s=t[e]??(t[e]={});if(jr(s,o),n&&(s.id=n),r&&(s.type=r),a){let e=s.custom??={name:a.name??``,input:``};a.name&&(e.name=a.name),a.input&&(e.input+=a.input)}if(i){let e=s.function??={name:i.name??``,arguments:``};i.name&&(e.name=i.name),i.arguments&&(e.arguments+=i.arguments,Mn(c(this,B,`f`),s)&&(e.parsed_arguments=_r(e.arguments)))}}}}return o},Symbol.asyncIterator)](){return this._createIterator(e=>{let t=t=>e(t);return this.on(`chunk`,t),()=>this.off(`chunk`,t)},{onReturn:()=>this.abort()})}toReadableStream(){return new Ve(this[Symbol.asyncIterator].bind(this),this.controller).toReadableStream()}};function Nr(e,t,n){let{id:r,choices:i,created:a,model:o,system_fingerprint:s,...c}=e;return On({...c,id:r,choices:i.map(({message:t,finish_reason:r,index:i,logprobs:a,...o})=>{let{content:s=null,function_call:c,tool_calls:u,audio:d,...p}=t,m=r??(n.has(i)&&Pr(d)?`stop`:null);if(!m)throw new f(`missing finish_reason for choice ${i}`);let h=d?{audio:d}:{},g=t.role;if(!g)throw new f(`missing role for choice ${i}`);if(c){let{arguments:e,name:n}=c;if(e==null)throw new f(`missing function_call.arguments for choice ${i}`);if(!n)throw new f(`missing function_call.name for choice ${i}`);return{...o,message:{...h,content:s,function_call:{arguments:e,name:n},role:g,refusal:t.refusal??null},finish_reason:m,index:i,logprobs:a}}return u?{...o,index:i,finish_reason:m,logprobs:a,message:{...p,...h,role:g,content:s,refusal:t.refusal??null,tool_calls:u.map((t,n)=>{if(t.type==null)throw new f(`missing choices[${i}].tool_calls[${n}].type\n${Fr(e)}`);if(t.type===`custom`){let{custom:r,type:a,id:o,...s}=t,{input:c=``,name:u,...d}=r||{};if(u==null)throw new f(`missing choices[${i}].tool_calls[${n}].custom.name\n${Fr(e)}`);return{...s,id:o||`call_${l()}`,type:a,custom:{...d,name:u,input:c}}}let{function:r,type:a,id:o,...s}=t,{arguments:c,name:u,...d}=r||{};if(u==null)throw new f(`missing choices[${i}].tool_calls[${n}].function.name\n${Fr(e)}`);if(c==null)throw new f(`missing choices[${i}].tool_calls[${n}].function.arguments\n${Fr(e)}`);return{...s,id:o||`call_${l()}`,type:a,function:{...d,name:u,arguments:c}}})}}:{...o,message:{...p,...h,content:s,role:g,refusal:t.refusal??null},finish_reason:m,index:i,logprobs:a}}),created:a,model:o,object:`chat.completion`,...s?{system_fingerprint:s}:{}},t)}function Pr(e){return e?.id!=null&&e.data!=null&&e.transcript!=null&&e.expires_at!=null}function Fr(e){return JSON.stringify(e)}var Ir=class e extends Mr{static fromReadableStream(t){let n=new e(null);return n._run(()=>n._fromReadableStream(t)),n}toReadableStream(){let e,t,n=this._createIterator(n=>{let r=t=>{e=t,n(t)},i=r=>{if(Fn(r)){t=r.tool_calls?.map(e=>e.id);return}if(In(r)){if(!e)throw new f(`cannot serialize a tool message before receiving any chunks`);n(Or(e,r,t))}};return this.on(`chunk`,r),this.on(`message`,i),()=>{this.off(`chunk`,r),this.off(`message`,i)}},{onReturn:()=>this.abort()});return new Ve(()=>n,this.controller).toReadableStream()}static runTools(t,n,r){let i=new e(n),a={...r,__metadata:{...r?.__metadata,helperMethod:`runTools`}};return i._run(()=>i._runTools(t,n,i,a)),i}},Lr=class extends F{constructor(){super(...arguments),this.messages=new Sn(this._client)}create(e,t){return this._client.post(`/chat/completions`,{body:e,...t,stream:e.stream??!1,__security:{bearerAuth:!0}})}retrieve(e,t){return this._client.get(I`/chat/completions/${e}`,{...t,__security:{bearerAuth:!0}})}update(e,t,n){return this._client.post(I`/chat/completions/${e}`,{body:t,...n,__security:{bearerAuth:!0}})}list(e={},t){return this._client.getAPIList(`/chat/completions`,j,{query:e,...t,__security:{bearerAuth:!0}})}delete(e,t){return this._client.delete(I`/chat/completions/${e}`,{...t,__security:{bearerAuth:!0}})}parse(e,t){return Pn(e.tools),this._client.chat.completions.create(e,{...t,__metadata:{...t?.__metadata,helperMethod:`chat.completions.parse`}})._thenUnwrap(t=>kn(t,e))}runTools(e,t){return e.stream?Ir.runTools(this._client,e,t):fr.runTools(this._client,e,t)}stream(e,t){return Mr.createChatCompletion(this._client,e,t)}};Lr.Messages=Sn;var Rr=class extends F{constructor(){super(...arguments),this.completions=new Lr(this._client)}};Rr.Completions=Lr;var zr=class extends F{create(e,t){return this._client.post(`/organization/admin_api_keys`,{body:e,...t,__security:{adminAPIKeyAuth:!0}})}retrieve(e,t){return this._client.get(I`/organization/admin_api_keys/${e}`,{...t,__security:{adminAPIKeyAuth:!0}})}list(e={},t){return this._client.getAPIList(`/organization/admin_api_keys`,j,{query:e,...t,__security:{adminAPIKeyAuth:!0}})}delete(e,t){return this._client.delete(I`/organization/admin_api_keys/${e}`,{...t,__security:{adminAPIKeyAuth:!0}})}},Br=class extends F{list(e={},t){return this._client.getAPIList(`/organization/audit_logs`,M,{query:e,...t,__security:{adminAPIKeyAuth:!0}})}},Vr=class extends F{create(e,t){return this._client.post(`/organization/certificates`,{body:e,...t,__security:{adminAPIKeyAuth:!0}})}retrieve(e,t={},n){return this._client.get(I`/organization/certificates/${e}`,{query:t,...n,__security:{adminAPIKeyAuth:!0}})}update(e,t,n){return this._client.post(I`/organization/certificates/${e}`,{body:t,...n,__security:{adminAPIKeyAuth:!0}})}list(e={},t){return this._client.getAPIList(`/organization/certificates`,M,{query:e,...t,__security:{adminAPIKeyAuth:!0}})}delete(e,t){return this._client.delete(I`/organization/certificates/${e}`,{...t,__security:{adminAPIKeyAuth:!0}})}activate(e,t){return this._client.getAPIList(`/organization/certificates/activate`,kt,{body:e,method:`post`,...t,__security:{adminAPIKeyAuth:!0}})}deactivate(e,t){return this._client.getAPIList(`/organization/certificates/deactivate`,kt,{body:e,method:`post`,...t,__security:{adminAPIKeyAuth:!0}})}},Hr=class extends F{retrieve(e){return this._client.get(`/organization/data_retention`,{...e,__security:{adminAPIKeyAuth:!0}})}update(e,t){return this._client.post(`/organization/data_retention`,{body:e,...t,__security:{adminAPIKeyAuth:!0}})}},Ur=class extends F{create(e,t){return this._client.post(`/organization/invites`,{body:e,...t,__security:{adminAPIKeyAuth:!0}})}retrieve(e,t){return this._client.get(I`/organization/invites/${e}`,{...t,__security:{adminAPIKeyAuth:!0}})}list(e={},t){return this._client.getAPIList(`/organization/invites`,M,{query:e,...t,__security:{adminAPIKeyAuth:!0}})}delete(e,t){return this._client.delete(I`/organization/invites/${e}`,{...t,__security:{adminAPIKeyAuth:!0}})}},Wr=class extends F{create(e,t){return this._client.post(`/organization/roles`,{body:e,...t,__security:{adminAPIKeyAuth:!0}})}retrieve(e,t){return this._client.get(I`/organization/roles/${e}`,{...t,__security:{adminAPIKeyAuth:!0}})}update(e,t,n){return this._client.post(I`/organization/roles/${e}`,{body:t,...n,__security:{adminAPIKeyAuth:!0}})}list(e={},t){return this._client.getAPIList(`/organization/roles`,At,{query:e,...t,__security:{adminAPIKeyAuth:!0}})}delete(e,t){return this._client.delete(I`/organization/roles/${e}`,{...t,__security:{adminAPIKeyAuth:!0}})}},Gr=class extends F{create(e,t){return this._client.post(`/organization/spend_alerts`,{body:e,...t,__security:{adminAPIKeyAuth:!0}})}retrieve(e,t){return this._client.get(I`/organization/spend_alerts/${e}`,{...t,__security:{adminAPIKeyAuth:!0}})}update(e,t,n){return this._client.post(I`/organization/spend_alerts/${e}`,{body:t,...n,__security:{adminAPIKeyAuth:!0}})}list(e={},t){return this._client.getAPIList(`/organization/spend_alerts`,M,{query:e,...t,__security:{adminAPIKeyAuth:!0}})}delete(e,t){return this._client.delete(I`/organization/spend_alerts/${e}`,{...t,__security:{adminAPIKeyAuth:!0}})}},Kr=class extends F{retrieve(e){return this._client.get(`/organization/spend_limit`,{...e,__security:{adminAPIKeyAuth:!0}})}update(e,t){return this._client.post(`/organization/spend_limit`,{body:e,...t,__security:{adminAPIKeyAuth:!0}})}delete(e){return this._client.delete(`/organization/spend_limit`,{...e,__security:{adminAPIKeyAuth:!0}})}},qr=class extends F{audioSpeeches(e,t){return this._client.get(`/organization/usage/audio_speeches`,{query:e,...t,__security:{adminAPIKeyAuth:!0}})}audioTranscriptions(e,t){return this._client.get(`/organization/usage/audio_transcriptions`,{query:e,...t,__security:{adminAPIKeyAuth:!0}})}codeInterpreterSessions(e,t){return this._client.get(`/organization/usage/code_interpreter_sessions`,{query:e,...t,__security:{adminAPIKeyAuth:!0}})}completions(e,t){return this._client.get(`/organization/usage/completions`,{query:e,...t,__security:{adminAPIKeyAuth:!0}})}costs(e,t){return this._client.get(`/organization/costs`,{query:e,...t,__security:{adminAPIKeyAuth:!0}})}embeddings(e,t){return this._client.get(`/organization/usage/embeddings`,{query:e,...t,__security:{adminAPIKeyAuth:!0}})}fileSearchCalls(e,t){return this._client.get(`/organization/usage/file_search_calls`,{query:e,...t,__security:{adminAPIKeyAuth:!0}})}images(e,t){return this._client.get(`/organization/usage/images`,{query:e,...t,__security:{adminAPIKeyAuth:!0}})}moderations(e,t){return this._client.get(`/organization/usage/moderations`,{query:e,...t,__security:{adminAPIKeyAuth:!0}})}vectorStores(e,t){return this._client.get(`/organization/usage/vector_stores`,{query:e,...t,__security:{adminAPIKeyAuth:!0}})}webSearchCalls(e,t){return this._client.get(`/organization/usage/web_search_calls`,{query:e,...t,__security:{adminAPIKeyAuth:!0}})}},Jr=class extends F{create(e,t,n){return this._client.post(I`/organization/groups/${e}/roles`,{body:t,...n,__security:{adminAPIKeyAuth:!0}})}retrieve(e,t,n){let{group_id:r}=t;return this._client.get(I`/organization/groups/${r}/roles/${e}`,{...n,__security:{adminAPIKeyAuth:!0}})}list(e,t={},n){return this._client.getAPIList(I`/organization/groups/${e}/roles`,At,{query:t,...n,__security:{adminAPIKeyAuth:!0}})}delete(e,t,n){let{group_id:r}=t;return this._client.delete(I`/organization/groups/${r}/roles/${e}`,{...n,__security:{adminAPIKeyAuth:!0}})}},Yr=class extends F{create(e,t,n){return this._client.post(I`/organization/groups/${e}/users`,{body:t,...n,__security:{adminAPIKeyAuth:!0}})}retrieve(e,t,n){let{group_id:r}=t;return this._client.get(I`/organization/groups/${r}/users/${e}`,{...n,__security:{adminAPIKeyAuth:!0}})}list(e,t={},n){return this._client.getAPIList(I`/organization/groups/${e}/users`,At,{query:t,...n,__security:{adminAPIKeyAuth:!0}})}delete(e,t,n){let{group_id:r}=t;return this._client.delete(I`/organization/groups/${r}/users/${e}`,{...n,__security:{adminAPIKeyAuth:!0}})}},Xr=class extends F{constructor(){super(...arguments),this.users=new Yr(this._client),this.roles=new Jr(this._client)}create(e,t){return this._client.post(`/organization/groups`,{body:e,...t,__security:{adminAPIKeyAuth:!0}})}retrieve(e,t){return this._client.get(I`/organization/groups/${e}`,{...t,__security:{adminAPIKeyAuth:!0}})}update(e,t,n){return this._client.post(I`/organization/groups/${e}`,{body:t,...n,__security:{adminAPIKeyAuth:!0}})}list(e={},t){return this._client.getAPIList(`/organization/groups`,At,{query:e,...t,__security:{adminAPIKeyAuth:!0}})}delete(e,t){return this._client.delete(I`/organization/groups/${e}`,{...t,__security:{adminAPIKeyAuth:!0}})}};Xr.Users=Yr,Xr.Roles=Jr;var Zr=class extends F{retrieve(e,t,n){let{project_id:r}=t;return this._client.get(I`/organization/projects/${r}/api_keys/${e}`,{...n,__security:{adminAPIKeyAuth:!0}})}list(e,t={},n){return this._client.getAPIList(I`/organization/projects/${e}/api_keys`,M,{query:t,...n,__security:{adminAPIKeyAuth:!0}})}delete(e,t,n){let{project_id:r}=t;return this._client.delete(I`/organization/projects/${r}/api_keys/${e}`,{...n,__security:{adminAPIKeyAuth:!0}})}},Qr=class extends F{list(e,t={},n){return this._client.getAPIList(I`/organization/projects/${e}/certificates`,M,{query:t,...n,__security:{adminAPIKeyAuth:!0}})}activate(e,t,n){return this._client.getAPIList(I`/organization/projects/${e}/certificates/activate`,kt,{body:t,method:`post`,...n,__security:{adminAPIKeyAuth:!0}})}deactivate(e,t,n){return this._client.getAPIList(I`/organization/projects/${e}/certificates/deactivate`,kt,{body:t,method:`post`,...n,__security:{adminAPIKeyAuth:!0}})}},$r=class extends F{retrieve(e,t){return this._client.get(I`/organization/projects/${e}/data_retention`,{...t,__security:{adminAPIKeyAuth:!0}})}update(e,t,n){return this._client.post(I`/organization/projects/${e}/data_retention`,{body:t,...n,__security:{adminAPIKeyAuth:!0}})}},ei=class extends F{retrieve(e,t){return this._client.get(I`/organization/projects/${e}/hosted_tool_permissions`,{...t,__security:{adminAPIKeyAuth:!0}})}update(e,t,n){return this._client.post(I`/organization/projects/${e}/hosted_tool_permissions`,{body:t,...n,__security:{adminAPIKeyAuth:!0}})}},ti=class extends F{retrieve(e,t){return this._client.get(I`/organization/projects/${e}/model_permissions`,{...t,__security:{adminAPIKeyAuth:!0}})}update(e,t,n){return this._client.post(I`/organization/projects/${e}/model_permissions`,{body:t,...n,__security:{adminAPIKeyAuth:!0}})}delete(e,t){return this._client.delete(I`/organization/projects/${e}/model_permissions`,{...t,__security:{adminAPIKeyAuth:!0}})}},ni=class extends F{listRateLimits(e,t={},n){return this._client.getAPIList(I`/organization/projects/${e}/rate_limits`,M,{query:t,...n,__security:{adminAPIKeyAuth:!0}})}updateRateLimit(e,t,n){let{project_id:r,...i}=t;return this._client.post(I`/organization/projects/${r}/rate_limits/${e}`,{body:i,...n,__security:{adminAPIKeyAuth:!0}})}},ri=class extends F{create(e,t,n){return this._client.post(I`/projects/${e}/roles`,{body:t,...n,__security:{adminAPIKeyAuth:!0}})}retrieve(e,t,n){let{project_id:r}=t;return this._client.get(I`/projects/${r}/roles/${e}`,{...n,__security:{adminAPIKeyAuth:!0}})}update(e,t,n){let{project_id:r,...i}=t;return this._client.post(I`/projects/${r}/roles/${e}`,{body:i,...n,__security:{adminAPIKeyAuth:!0}})}list(e,t={},n){return this._client.getAPIList(I`/projects/${e}/roles`,At,{query:t,...n,__security:{adminAPIKeyAuth:!0}})}delete(e,t,n){let{project_id:r}=t;return this._client.delete(I`/projects/${r}/roles/${e}`,{...n,__security:{adminAPIKeyAuth:!0}})}},ii=class extends F{create(e,t,n){return this._client.post(I`/organization/projects/${e}/spend_alerts`,{body:t,...n,__security:{adminAPIKeyAuth:!0}})}retrieve(e,t,n){let{project_id:r}=t;return this._client.get(I`/organization/projects/${r}/spend_alerts/${e}`,{...n,__security:{adminAPIKeyAuth:!0}})}update(e,t,n){let{project_id:r,...i}=t;return this._client.post(I`/organization/projects/${r}/spend_alerts/${e}`,{body:i,...n,__security:{adminAPIKeyAuth:!0}})}list(e,t={},n){return this._client.getAPIList(I`/organization/projects/${e}/spend_alerts`,M,{query:t,...n,__security:{adminAPIKeyAuth:!0}})}delete(e,t,n){let{project_id:r}=t;return this._client.delete(I`/organization/projects/${r}/spend_alerts/${e}`,{...n,__security:{adminAPIKeyAuth:!0}})}},ai=class extends F{retrieve(e,t){return this._client.get(I`/organization/projects/${e}/spend_limit`,{...t,__security:{adminAPIKeyAuth:!0}})}update(e,t,n){return this._client.post(I`/organization/projects/${e}/spend_limit`,{body:t,...n,__security:{adminAPIKeyAuth:!0}})}delete(e,t){return this._client.delete(I`/organization/projects/${e}/spend_limit`,{...t,__security:{adminAPIKeyAuth:!0}})}},oi=class extends F{create(e,t,n){let{project_id:r,...i}=t;return this._client.post(I`/projects/${r}/groups/${e}/roles`,{body:i,...n,__security:{adminAPIKeyAuth:!0}})}retrieve(e,t,n){let{project_id:r,group_id:i}=t;return this._client.get(I`/projects/${r}/groups/${i}/roles/${e}`,{...n,__security:{adminAPIKeyAuth:!0}})}list(e,t,n){let{project_id:r,...i}=t;return this._client.getAPIList(I`/projects/${r}/groups/${e}/roles`,At,{query:i,...n,__security:{adminAPIKeyAuth:!0}})}delete(e,t,n){let{project_id:r,group_id:i}=t;return this._client.delete(I`/projects/${r}/groups/${i}/roles/${e}`,{...n,__security:{adminAPIKeyAuth:!0}})}},si=class extends F{constructor(){super(...arguments),this.roles=new oi(this._client)}create(e,t,n){return this._client.post(I`/organization/projects/${e}/groups`,{body:t,...n,__security:{adminAPIKeyAuth:!0}})}retrieve(e,t,n){let{project_id:r,...i}=t;return this._client.get(I`/organization/projects/${r}/groups/${e}`,{query:i,...n,__security:{adminAPIKeyAuth:!0}})}list(e,t={},n){return this._client.getAPIList(I`/organization/projects/${e}/groups`,At,{query:t,...n,__security:{adminAPIKeyAuth:!0}})}delete(e,t,n){let{project_id:r}=t;return this._client.delete(I`/organization/projects/${r}/groups/${e}`,{...n,__security:{adminAPIKeyAuth:!0}})}};si.Roles=oi;var ci=class extends F{create(e,t,n){let{project_id:r,...i}=t;return this._client.post(I`/organization/projects/${r}/service_accounts/${e}/api_keys`,{body:i,...n,__security:{adminAPIKeyAuth:!0}})}},li=class extends F{constructor(){super(...arguments),this.apiKeys=new ci(this._client)}create(e,t,n){return this._client.post(I`/organization/projects/${e}/service_accounts`,{body:t,...n,__security:{adminAPIKeyAuth:!0}})}retrieve(e,t,n){let{project_id:r}=t;return this._client.get(I`/organization/projects/${r}/service_accounts/${e}`,{...n,__security:{adminAPIKeyAuth:!0}})}update(e,t,n){let{project_id:r,...i}=t;return this._client.post(I`/organization/projects/${r}/service_accounts/${e}`,{body:i,...n,__security:{adminAPIKeyAuth:!0}})}list(e,t={},n){return this._client.getAPIList(I`/organization/projects/${e}/service_accounts`,M,{query:t,...n,__security:{adminAPIKeyAuth:!0}})}delete(e,t,n){let{project_id:r}=t;return this._client.delete(I`/organization/projects/${r}/service_accounts/${e}`,{...n,__security:{adminAPIKeyAuth:!0}})}};li.APIKeys=ci;var ui=class extends F{create(e,t,n){let{project_id:r,...i}=t;return this._client.post(I`/projects/${r}/users/${e}/roles`,{body:i,...n,__security:{adminAPIKeyAuth:!0}})}retrieve(e,t,n){let{project_id:r,user_id:i}=t;return this._client.get(I`/projects/${r}/users/${i}/roles/${e}`,{...n,__security:{adminAPIKeyAuth:!0}})}list(e,t,n){let{project_id:r,...i}=t;return this._client.getAPIList(I`/projects/${r}/users/${e}/roles`,At,{query:i,...n,__security:{adminAPIKeyAuth:!0}})}delete(e,t,n){let{project_id:r,user_id:i}=t;return this._client.delete(I`/projects/${r}/users/${i}/roles/${e}`,{...n,__security:{adminAPIKeyAuth:!0}})}},di=class extends F{constructor(){super(...arguments),this.roles=new ui(this._client)}create(e,t,n){return this._client.post(I`/organization/projects/${e}/users`,{body:t,...n,__security:{adminAPIKeyAuth:!0}})}retrieve(e,t,n){let{project_id:r}=t;return this._client.get(I`/organization/projects/${r}/users/${e}`,{...n,__security:{adminAPIKeyAuth:!0}})}update(e,t,n){let{project_id:r,...i}=t;return this._client.post(I`/organization/projects/${r}/users/${e}`,{body:i,...n,__security:{adminAPIKeyAuth:!0}})}list(e,t={},n){return this._client.getAPIList(I`/organization/projects/${e}/users`,M,{query:t,...n,__security:{adminAPIKeyAuth:!0}})}delete(e,t,n){let{project_id:r}=t;return this._client.delete(I`/organization/projects/${r}/users/${e}`,{...n,__security:{adminAPIKeyAuth:!0}})}};di.Roles=ui;var H=class extends F{constructor(){super(...arguments),this.users=new di(this._client),this.serviceAccounts=new li(this._client),this.apiKeys=new Zr(this._client),this.rateLimits=new ni(this._client),this.modelPermissions=new ti(this._client),this.hostedToolPermissions=new ei(this._client),this.groups=new si(this._client),this.roles=new ri(this._client),this.dataRetention=new $r(this._client),this.spendLimit=new ai(this._client),this.spendAlerts=new ii(this._client),this.certificates=new Qr(this._client)}create(e,t){return this._client.post(`/organization/projects`,{body:e,...t,__security:{adminAPIKeyAuth:!0}})}retrieve(e,t){return this._client.get(I`/organization/projects/${e}`,{...t,__security:{adminAPIKeyAuth:!0}})}update(e,t,n){return this._client.post(I`/organization/projects/${e}`,{body:t,...n,__security:{adminAPIKeyAuth:!0}})}list(e={},t){return this._client.getAPIList(`/organization/projects`,M,{query:e,...t,__security:{adminAPIKeyAuth:!0}})}archive(e,t){return this._client.post(I`/organization/projects/${e}/archive`,{...t,__security:{adminAPIKeyAuth:!0}})}};H.Users=di,H.ServiceAccounts=li,H.APIKeys=Zr,H.RateLimits=ni,H.ModelPermissions=ti,H.HostedToolPermissions=ei,H.Groups=si,H.Roles=ri,H.DataRetention=$r,H.SpendLimit=ai,H.SpendAlerts=ii,H.Certificates=Qr;var fi=class extends F{create(e,t,n){return this._client.post(I`/organization/users/${e}/roles`,{body:t,...n,__security:{adminAPIKeyAuth:!0}})}retrieve(e,t,n){let{user_id:r}=t;return this._client.get(I`/organization/users/${r}/roles/${e}`,{...n,__security:{adminAPIKeyAuth:!0}})}list(e,t={},n){return this._client.getAPIList(I`/organization/users/${e}/roles`,At,{query:t,...n,__security:{adminAPIKeyAuth:!0}})}delete(e,t,n){let{user_id:r}=t;return this._client.delete(I`/organization/users/${r}/roles/${e}`,{...n,__security:{adminAPIKeyAuth:!0}})}},pi=class extends F{constructor(){super(...arguments),this.roles=new fi(this._client)}retrieve(e,t){return this._client.get(I`/organization/users/${e}`,{...t,__security:{adminAPIKeyAuth:!0}})}update(e,t,n){return this._client.post(I`/organization/users/${e}`,{body:t,...n,__security:{adminAPIKeyAuth:!0}})}list(e={},t){return this._client.getAPIList(`/organization/users`,M,{query:e,...t,__security:{adminAPIKeyAuth:!0}})}delete(e,t){return this._client.delete(I`/organization/users/${e}`,{...t,__security:{adminAPIKeyAuth:!0}})}};pi.Roles=fi;var U=class extends F{constructor(){super(...arguments),this.auditLogs=new Br(this._client),this.adminAPIKeys=new zr(this._client),this.usage=new qr(this._client),this.invites=new Ur(this._client),this.users=new pi(this._client),this.groups=new Xr(this._client),this.roles=new Wr(this._client),this.dataRetention=new Hr(this._client),this.spendLimit=new Kr(this._client),this.spendAlerts=new Gr(this._client),this.certificates=new Vr(this._client),this.projects=new H(this._client)}};U.AuditLogs=Br,U.AdminAPIKeys=zr,U.Usage=qr,U.Invites=Ur,U.Users=pi,U.Groups=Xr,U.Roles=Wr,U.DataRetention=Hr,U.SpendLimit=Kr,U.SpendAlerts=Gr,U.Certificates=Vr,U.Projects=H;var mi=class extends F{constructor(){super(...arguments),this.organization=new U(this._client)}};mi.Organization=U;var hi=class extends F{create(e,t){return this._client.post(`/audio/speech`,{body:e,...t,headers:N([{Accept:`application/octet-stream`},t?.headers]),__security:{bearerAuth:!0},__binaryResponse:!0})}},gi=class extends F{create(e,t){return this._client.post(`/audio/transcriptions`,P({body:e,...t,stream:e.stream??!1,__metadata:{model:e.model},__security:{bearerAuth:!0}},this._client))}},_i=class extends F{create(e,t){return this._client.post(`/audio/translations`,P({body:e,...t,__metadata:{model:e.model},__security:{bearerAuth:!0}},this._client))}},vi=class extends F{constructor(){super(...arguments),this.transcriptions=new gi(this._client),this.translations=new _i(this._client),this.speech=new hi(this._client)}};vi.Transcriptions=gi,vi.Translations=_i,vi.Speech=hi;var yi=class extends F{create(e,t){return this._client.post(`/batches`,{body:e,...t,__security:{bearerAuth:!0}})}retrieve(e,t){return this._client.get(I`/batches/${e}`,{...t,__security:{bearerAuth:!0}})}list(e={},t){return this._client.getAPIList(`/batches`,j,{query:e,...t,__security:{bearerAuth:!0}})}cancel(e,t){return this._client.post(I`/batches/${e}/cancel`,{...t,__security:{bearerAuth:!0}})}},bi=class extends F{create(e,t){return this._client.post(`/assistants`,{body:e,...t,headers:N([{"OpenAI-Beta":`assistants=v2`},t?.headers]),__security:{bearerAuth:!0}})}retrieve(e,t){return this._client.get(I`/assistants/${e}`,{...t,headers:N([{"OpenAI-Beta":`assistants=v2`},t?.headers]),__security:{bearerAuth:!0}})}update(e,t,n){return this._client.post(I`/assistants/${e}`,{body:t,...n,headers:N([{"OpenAI-Beta":`assistants=v2`},n?.headers]),__security:{bearerAuth:!0}})}list(e={},t){return this._client.getAPIList(`/assistants`,j,{query:e,...t,headers:N([{"OpenAI-Beta":`assistants=v2`},t?.headers]),__security:{bearerAuth:!0}})}delete(e,t){return this._client.delete(I`/assistants/${e}`,{...t,headers:N([{"OpenAI-Beta":`assistants=v2`},t?.headers]),__security:{bearerAuth:!0}})}},xi=class extends F{create(e,t){return this._client.post(`/realtime/sessions`,{body:e,...t,headers:N([{"OpenAI-Beta":`assistants=v2`},t?.headers]),__security:{bearerAuth:!0}})}},Si=class extends F{create(e,t){return this._client.post(`/realtime/transcription_sessions`,{body:e,...t,headers:N([{"OpenAI-Beta":`assistants=v2`},t?.headers]),__security:{bearerAuth:!0}})}},Ci=class extends F{constructor(){super(...arguments),this.sessions=new xi(this._client),this.transcriptionSessions=new Si(this._client)}};Ci.Sessions=xi,Ci.TranscriptionSessions=Si;var wi=class extends F{create(e,t){return this._client.post(`/chatkit/sessions`,{body:e,...t,headers:N([{"OpenAI-Beta":`chatkit_beta=v1`},t?.headers]),__security:{bearerAuth:!0}})}cancel(e,t){return this._client.post(I`/chatkit/sessions/${e}/cancel`,{...t,headers:N([{"OpenAI-Beta":`chatkit_beta=v1`},t?.headers]),__security:{bearerAuth:!0}})}},Ti=class extends F{retrieve(e,t){return this._client.get(I`/chatkit/threads/${e}`,{...t,headers:N([{"OpenAI-Beta":`chatkit_beta=v1`},t?.headers]),__security:{bearerAuth:!0}})}list(e={},t){return this._client.getAPIList(`/chatkit/threads`,M,{query:e,...t,headers:N([{"OpenAI-Beta":`chatkit_beta=v1`},t?.headers]),__security:{bearerAuth:!0}})}delete(e,t){return this._client.delete(I`/chatkit/threads/${e}`,{...t,headers:N([{"OpenAI-Beta":`chatkit_beta=v1`},t?.headers]),__security:{bearerAuth:!0}})}listItems(e,t={},n){return this._client.getAPIList(I`/chatkit/threads/${e}/items`,M,{query:t,...n,headers:N([{"OpenAI-Beta":`chatkit_beta=v1`},n?.headers]),__security:{bearerAuth:!0}})}},Ei=class extends F{constructor(){super(...arguments),this.sessions=new wi(this._client),this.threads=new Ti(this._client)}};Ei.Sessions=wi,Ei.Threads=Ti;var Di=class extends F{list(e,t={},n){let{betas:r,...i}=t??{};return this._client.getAPIList(I`/responses/${e}/input_items?beta=true`,j,{query:i,...n,headers:N([{...r?.toString()==null?void 0:{"openai-beta":r?.toString()}},n?.headers]),__security:{bearerAuth:!0}})}},Oi=class extends F{count(e={},t){let{betas:n,...r}=e??{};return this._client.post(`/responses/input_tokens?beta=true`,{body:r,...t,headers:N([{...n?.toString()==null?void 0:{"openai-beta":n?.toString()}},t?.headers]),__security:{bearerAuth:!0}})}},ki=class extends F{constructor(){super(...arguments),this.inputItems=new Di(this._client),this.inputTokens=new Oi(this._client)}create(e,t){let{betas:n,...r}=e;return this._client.post(`/responses?beta=true`,{body:r,...t,headers:N([{...n?.toString()==null?void 0:{"openai-beta":n?.toString()}},t?.headers]),stream:e.stream??!1,__security:{bearerAuth:!0}})}retrieve(e,t={},n){let{betas:r,...i}=t??{};return this._client.get(I`/responses/${e}?beta=true`,{query:i,...n,headers:N([{...r?.toString()==null?void 0:{"openai-beta":r?.toString()}},n?.headers]),stream:t?.stream??!1,__security:{bearerAuth:!0}})}delete(e,t={},n){let{betas:r}=t??{};return this._client.delete(I`/responses/${e}?beta=true`,{...n,headers:N([{Accept:`*/*`,...r?.toString()==null?void 0:{"openai-beta":r?.toString()}},n?.headers]),__security:{bearerAuth:!0}})}cancel(e,t={},n){let{betas:r}=t??{};return this._client.post(I`/responses/${e}/cancel?beta=true`,{...n,headers:N([{...r?.toString()==null?void 0:{"openai-beta":r?.toString()}},n?.headers]),__security:{bearerAuth:!0}})}compact(e,t){let{betas:n,...r}=e;return this._client.post(`/responses/compact?beta=true`,{body:r,...t,headers:N([{...n?.toString()==null?void 0:{"openai-beta":n?.toString()}},t?.headers]),__security:{bearerAuth:!0}})}};ki.InputItems=Di,ki.InputTokens=Oi;var Ai=class extends F{create(e,t,n){return this._client.post(I`/threads/${e}/messages`,{body:t,...n,headers:N([{"OpenAI-Beta":`assistants=v2`},n?.headers]),__security:{bearerAuth:!0}})}retrieve(e,t,n){let{thread_id:r}=t;return this._client.get(I`/threads/${r}/messages/${e}`,{...n,headers:N([{"OpenAI-Beta":`assistants=v2`},n?.headers]),__security:{bearerAuth:!0}})}update(e,t,n){let{thread_id:r,...i}=t;return this._client.post(I`/threads/${r}/messages/${e}`,{body:i,...n,headers:N([{"OpenAI-Beta":`assistants=v2`},n?.headers]),__security:{bearerAuth:!0}})}list(e,t={},n){return this._client.getAPIList(I`/threads/${e}/messages`,j,{query:t,...n,headers:N([{"OpenAI-Beta":`assistants=v2`},n?.headers]),__security:{bearerAuth:!0}})}delete(e,t,n){let{thread_id:r}=t;return this._client.delete(I`/threads/${r}/messages/${e}`,{...n,headers:N([{"OpenAI-Beta":`assistants=v2`},n?.headers]),__security:{bearerAuth:!0}})}},ji=class extends F{retrieve(e,t,n){let{thread_id:r,run_id:i,...a}=t;return this._client.get(I`/threads/${r}/runs/${i}/steps/${e}`,{query:a,...n,headers:N([{"OpenAI-Beta":`assistants=v2`},n?.headers]),__security:{bearerAuth:!0}})}list(e,t,n){let{thread_id:r,...i}=t;return this._client.getAPIList(I`/threads/${r}/runs/${e}/steps`,j,{query:i,...n,headers:N([{"OpenAI-Beta":`assistants=v2`},n?.headers]),__security:{bearerAuth:!0}})}};const Mi=e=>{if(globalThis.Buffer!==void 0){let t=globalThis.Buffer.from(e,`base64`);return new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}if(typeof atob<`u`){let t=atob(e),n=new Uint8Array(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n}throw new f("Cannot decode base64 string; Expected `Buffer` or `atob` to be defined")},Ni=e=>{if(typeof Buffer<`u`){let t=Buffer.from(e,`base64`);return Array.from(new Float32Array(t.buffer,t.byteOffset,t.length/Float32Array.BYTES_PER_ELEMENT))}{let t=atob(e),n=t.length,r=new Uint8Array(n);for(let e=0;e<n;e++)r[e]=t.charCodeAt(e);return Array.from(new Float32Array(r.buffer))}},W=e=>{if(globalThis.process!==void 0)return{}[e]?.trim()||void 0;if(globalThis.Deno!==void 0)return globalThis.Deno.env?.get?.(e)?.trim()||void 0},Pi=1024,Fi=new WeakMap,Ii=new WeakSet;function Li(e){return{arrays:new Map,cacheArrays:e,records:new WeakMap}}function Ri(e){for(let[t,n]of e.arrays)n.cacheable&&!Ii.has(t)?Fi.set(t,{length:n.length,ownEntryCount:n.ownEntryCount}):Fi.delete(t)}function zi(e){return typeof e==`string`||typeof e==`number`}function Bi(e,t){return t.every(zi)&&e.every(zi)}function Vi(e){let t=0;for(let n of Object.keys(e)){let r=Number(n);Number.isSafeInteger(r)&&r>=0&&r<e.length&&String(r)===n&&(t+=1)}return t}function Hi(e,t,n){return t?n?.length===e.length?n.ownEntryCount:Vi(e):0}function Ui(e,t,n){let{index:r}=e;if(t===`array`&&r==null)throw console.error(e),Error("Expected array delta entry to have an `index` property");if(t===`array`&&typeof r!=`number`)throw TypeError(`Expected array delta entry \`index\` property to be a number but got ${r}`);if(!Number.isSafeInteger(r)||r<0||r>=n+Pi||r>=65536)throw new f(`Assistant stream delta contains an invalid ${t} index: ${r}`);return r}function Wi(e,t,n,r,i){let a=r.arrays.get(e);if(!a){let t=r.cacheArrays&&!Ii.has(e),n=t?Fi.get(e):void 0;a={baselineLength:e.length,cacheable:t,enforceSparseHoleBudget:t,entries:new Map,length:e.length,ownEntryCount:Hi(e,t,n)},r.arrays.set(e,a)}for(let o of t){if(!C(o))throw Error(`Expected array delta entry to be an object but got: ${o}`);let t=Ui(o,n,a.baselineLength),s;a.entries.has(t)?s=a.entries.get(t):pe(e,t)?(s=e[t],s??a.entries.set(t,o)):(a.entries.set(t,o),a.ownEntryCount+=1);let c=Math.max(a.length,t+1);if(a.enforceSparseHoleBudget&&c-a.ownEntryCount>Pi)throw new f(`Assistant stream delta contains an invalid ${n} index: ${t}`);C(s)&&i(s,o,r),a.length=c}}function Gi(e,t,n){let r=n.records.get(e);for(let[i,a]of Object.entries(t)){if(i===`index`||i===`type`)continue;let t;if(r?.has(i)?t=r.get(i):pe(e,i)&&(t=e[i]),t==null){r||(r=new Map,n.records.set(e,r)),r.set(i,a);continue}C(t)&&C(a)?Gi(t,a,n):Array.isArray(t)&&Array.isArray(a)&&!Bi(t,a)&&Wi(t,a,`array`,n,Gi)}}function Ki(e){return(C(e)||Array.isArray(e))&&Ii.has(e)}function G(e){if(!(!C(e)&&!Array.isArray(e)||Ii.has(e))){Ii.add(e),Array.isArray(e)&&Fi.delete(e);for(let t of Reflect.ownKeys(e)){let n=Object.getOwnPropertyDescriptor(e,t);n&&`value`in n&&G(n.value)}}}function qi(e,t,n){Ii.has(e)&&G(n),Object.defineProperty(e,t,{configurable:!0,enumerable:!0,value:n,writable:!0})}function Ji(e){let{index:t}=e;if(t==null)throw console.error(e),Error("Expected array delta entry to have an `index` property");if(typeof t!=`number`)throw TypeError(`Expected array delta entry \`index\` property to be a number but got ${t}`);return t}function Yi(e,t,n){if(Bi(e,t)){e.push(...t),Fi.delete(e);return}for(let r of t){if(!C(r))throw Error(`Expected array delta entry to be an object but got: ${r}`);let t=Ji(r);if(pe(e,t)){let i=e[t];i==null?(Ii.has(e)&&G(r),e[t]=r):e[t]=n(i,r)}else qi(e,t,r)}}function Xi(e,t){let n=Ii.has(e);for(let[r,i]of Object.entries(t)){if(r===`__proto__`||r===`constructor`||r===`prototype`)throw new f(`Assistant stream delta contains an unsafe property: ${r}`);if(!pe(e,r)){n&&G(i),e[r]=i;continue}let t=e[r];if(t==null){n&&G(i),e[r]=i;continue}if(r===`index`||r===`type`){e[r]=i;continue}if(typeof t==`string`&&typeof i==`string`)t+=i;else if(typeof t==`number`&&typeof i==`number`)t+=i;else if(C(t)&&C(i))t=Xi(t,i);else if(Array.isArray(t)&&Array.isArray(i)){Yi(t,i,Xi);continue}else throw TypeError(`Unhandled record type: ${r}, deltaValue: ${i}, accValue: ${t}`);e[r]=t}return e}function Zi(e){if(!(!C(e)&&!Array.isArray(e)))for(let[t,n]of Object.entries(e)){if(t===`__proto__`||t===`constructor`||t===`prototype`)throw new f(`Assistant stream delta contains an unsafe property: ${t}`);Zi(n)}}function Qi(e,t,n=!1){Zi(t);let r=e,i=t,a=Li(n&&!Ki(e));return Gi(r,i,a),Xi(r,i),Ri(a),e}function $i(e,t,n,r=!0){Zi(t);let i=Li(r&&!Ki(e));return Wi(e,t,n,i,Gi),()=>Ri(i)}var K,ea,q,ta,J,na,ra,ia,aa,Y,oa,sa,ca,la,ua,da,fa,X,pa,ma,ha,ga,_a,va=class e extends $n{constructor(){super(...arguments),K.add(this),ea.set(this,[]),q.set(this,Object.create(null)),ta.set(this,Object.create(null)),J.set(this,void 0),na.set(this,void 0),ra.set(this,void 0),ia.set(this,void 0),aa.set(this,void 0),Y.set(this,void 0),oa.set(this,void 0),sa.set(this,void 0),ca.set(this,void 0)}[(ea=new WeakMap,q=new WeakMap,ta=new WeakMap,J=new WeakMap,na=new WeakMap,ra=new WeakMap,ia=new WeakMap,aa=new WeakMap,Y=new WeakMap,oa=new WeakMap,sa=new WeakMap,ca=new WeakMap,K=new WeakSet,Symbol.asyncIterator)](){return this._createIterator(e=>{let t=t=>e(structuredClone(t));return this.on(`event`,t),()=>this.off(`event`,t)},{onReturn:()=>this.abort()})}static fromReadableStream(t){let n=new e;return n._run(()=>n._fromReadableStream(t)),n}async _fromReadableStream(e,t){this._listenForAbort(t?.signal),this._connected();let n=Ve.fromReadableStream(e,this.controller);for await(let e of n)c(this,K,`m`,la).call(this,e);if(n.controller.signal?.aborted)throw new m;return this._addRun(c(this,K,`m`,ua).call(this))}toReadableStream(){return new Ve(this[Symbol.asyncIterator].bind(this),this.controller).toReadableStream()}static createToolAssistantStream(t,n,r,i){let a=new e;return a._run(()=>a._runToolAssistantStream(t,n,r,{...i,__metadata:{...i?.__metadata,helperMethod:`stream`}})),a}async _createToolAssistantStream(e,t,n,r){this._listenForAbort(r?.signal);let i={...n,stream:!0},a=await e.submitToolOutputs(t,i,{...r,signal:this.controller.signal});this._connected();for await(let e of a)c(this,K,`m`,la).call(this,e);if(a.controller.signal?.aborted)throw new m;return this._addRun(c(this,K,`m`,ua).call(this))}static createThreadAssistantStream(t,n,r){let i=new e;return i._run(()=>i._threadAssistantStream(t,n,{...r,__metadata:{...r?.__metadata,helperMethod:`stream`}})),i}static createAssistantStream(t,n,r,i){let a=new e;return a._run(()=>a._runAssistantStream(t,n,r,{...i,__metadata:{...i?.__metadata,helperMethod:`stream`}})),a}currentEvent(){return G(c(this,oa,`f`)),c(this,oa,`f`)}currentRun(){return G(c(this,sa,`f`)),c(this,sa,`f`)}currentMessageSnapshot(){return G(c(this,J,`f`)),c(this,J,`f`)}currentRunStepSnapshot(){return G(c(this,ca,`f`)),c(this,ca,`f`)}async finalRunSteps(){return await this.done(),Object.values(c(this,q,`f`))}async finalMessages(){return await this.done(),Object.values(c(this,ta,`f`))}async finalRun(){if(await this.done(),!c(this,na,`f`))throw Error(`Final run was not received.`);return c(this,na,`f`)}async _createThreadAssistantStream(e,t,n){this._listenForAbort(n?.signal);let r={...t,stream:!0},i=await e.createAndRun(r,{...n,signal:this.controller.signal});this._connected();for await(let e of i)c(this,K,`m`,la).call(this,e);if(i.controller.signal?.aborted)throw new m;return this._addRun(c(this,K,`m`,ua).call(this))}async _createAssistantStream(e,t,n,r){this._listenForAbort(r?.signal);let i={...n,stream:!0},a=await e.create(t,i,{...r,signal:this.controller.signal});this._connected();for await(let e of a)c(this,K,`m`,la).call(this,e);if(a.controller.signal?.aborted)throw new m;return this._addRun(c(this,K,`m`,ua).call(this))}static accumulateDelta(e,t){return Qi(e,t)}_addRun(e){return c(this,K,`m`,X).call(this,`run`,e),e}async _threadAssistantStream(e,t,n){return await this._createThreadAssistantStream(t,e,n)}async _runAssistantStream(e,t,n,r){return await this._createAssistantStream(t,e,n,r)}async _runToolAssistantStream(e,t,n,r){return await this._createToolAssistantStream(t,e,n,r)}};la=function(e){if(!this.ended)switch(s(this,oa,e,`f`),c(this,K,`m`,pa).call(this,e),e.event){case`thread.created`:break;case`thread.run.created`:case`thread.run.queued`:case`thread.run.in_progress`:case`thread.run.requires_action`:case`thread.run.completed`:case`thread.run.incomplete`:case`thread.run.failed`:case`thread.run.cancelling`:case`thread.run.cancelled`:case`thread.run.expired`:c(this,K,`m`,_a).call(this,e);break;case`thread.run.step.created`:case`thread.run.step.in_progress`:case`thread.run.step.delta`:case`thread.run.step.completed`:case`thread.run.step.failed`:case`thread.run.step.cancelled`:case`thread.run.step.expired`:c(this,K,`m`,fa).call(this,e);break;case`thread.message.created`:case`thread.message.in_progress`:case`thread.message.delta`:case`thread.message.completed`:case`thread.message.incomplete`:c(this,K,`m`,da).call(this,e);break;case`error`:throw Error(`Encountered an error event in event processing - errors should be processed earlier`)}},ua=function(){if(this.ended)throw new f(`stream has ended, this shouldn't happen`);if(!c(this,na,`f`))throw Error(`Final run has not been received`);return c(this,na,`f`)},da=function(e){let[t,n]=c(this,K,`m`,ha).call(this,e,c(this,J,`f`));s(this,J,t,`f`),c(this,ta,`f`)[t.id]=t;for(let e of n){let n=t.content[e.index];n?.type===`text`&&c(this,K,`m`,X).call(this,`textCreated`,n.text)}switch(e.event){case`thread.message.created`:s(this,ra,void 0,`f`),s(this,ia,void 0,`f`),c(this,K,`m`,X).call(this,`messageCreated`,e.data);break;case`thread.message.in_progress`:break;case`thread.message.delta`:if(c(this,K,`m`,X).call(this,`messageDelta`,e.data.delta,t),e.data.delta.content)for(let n of e.data.delta.content){if(n.type===`text`&&n.text){let e=n.text,r=t.content[n.index];if(r&&r.type===`text`)c(this,K,`m`,X).call(this,`textDelta`,e,r.text);else throw Error(`The snapshot associated with this text delta is not text or missing`)}if(n.index!==c(this,ra,`f`)){if(c(this,ia,`f`))switch(c(this,ia,`f`).type){case`text`:c(this,K,`m`,X).call(this,`textDone`,c(this,ia,`f`).text,c(this,J,`f`));break;case`image_file`:c(this,K,`m`,X).call(this,`imageFileDone`,c(this,ia,`f`).image_file,c(this,J,`f`))}s(this,ra,n.index,`f`)}s(this,ia,t.content[n.index],`f`)}break;case`thread.message.completed`:case`thread.message.incomplete`:if(c(this,ra,`f`)!==void 0){let t=e.data.content[c(this,ra,`f`)];if(t)switch(t.type){case`image_file`:c(this,K,`m`,X).call(this,`imageFileDone`,t.image_file,c(this,J,`f`));break;case`text`:c(this,K,`m`,X).call(this,`textDone`,t.text,c(this,J,`f`))}}c(this,J,`f`)&&c(this,K,`m`,X).call(this,`messageDone`,e.data),s(this,ra,void 0,`f`),s(this,ia,void 0,`f`),s(this,J,void 0,`f`)}},fa=function(e){let t=c(this,K,`m`,ma).call(this,e);switch(s(this,ca,t,`f`),e.event){case`thread.run.step.created`:s(this,aa,void 0,`f`),s(this,Y,void 0,`f`),c(this,K,`m`,X).call(this,`runStepCreated`,e.data);break;case`thread.run.step.delta`:{let n=e.data.delta;if(n.step_details&&n.step_details.type===`tool_calls`&&n.step_details.tool_calls&&t.step_details.type===`tool_calls`)for(let e of n.step_details.tool_calls)e.index===c(this,aa,`f`)?c(this,K,`m`,X).call(this,`toolCallDelta`,e,t.step_details.tool_calls[e.index]):(c(this,Y,`f`)&&c(this,K,`m`,X).call(this,`toolCallDone`,c(this,Y,`f`)),s(this,aa,e.index,`f`),s(this,Y,t.step_details.tool_calls[e.index],`f`),c(this,Y,`f`)&&c(this,K,`m`,X).call(this,`toolCallCreated`,c(this,Y,`f`)));c(this,K,`m`,X).call(this,`runStepDelta`,e.data.delta,t);break}case`thread.run.step.completed`:case`thread.run.step.failed`:case`thread.run.step.cancelled`:case`thread.run.step.expired`:s(this,ca,void 0,`f`),e.data.step_details.type===`tool_calls`&&c(this,Y,`f`)&&c(this,K,`m`,X).call(this,`toolCallDone`,c(this,Y,`f`)),c(this,K,`m`,X).call(this,`runStepDone`,e.data,t),s(this,aa,void 0,`f`),s(this,Y,void 0,`f`)}},X=function(e,...t){if(this._hasListeners(e))for(let e of t)G(e);this._emit(e,...t)},pa=function(e){c(this,ea,`f`).push(e),c(this,K,`m`,X).call(this,`event`,e)},ma=function(e){switch(e.event){case`thread.run.step.created`:return c(this,q,`f`)[e.data.id]=e.data,e.data;case`thread.run.step.delta`:{let t=c(this,q,`f`)[e.data.id];if(!t)throw Error(`Received a RunStepDelta before creation of a snapshot`);let n=e.data;if(n.delta){let r=Qi(t,n.delta,!0);c(this,q,`f`)[e.data.id]=r}return c(this,q,`f`)[e.data.id]}case`thread.run.step.completed`:case`thread.run.step.failed`:case`thread.run.step.cancelled`:case`thread.run.step.expired`:case`thread.run.step.in_progress`:c(this,q,`f`)[e.data.id]=e.data}if(c(this,q,`f`)[e.data.id])return c(this,q,`f`)[e.data.id];throw Error(`No snapshot available`)},ha=function(e,t){let n=[];switch(e.event){case`thread.message.created`:return[e.data,n];case`thread.message.delta`:{if(!t)throw Error(`Received a delta with no existing snapshot (there should be one from message creation)`);let r=e.data;if(r.delta.content){Zi(r.delta);let e=!Ki(t),i=$i(t.content,r.delta.content,`content`,e);for(let i of r.delta.content)if(pe(t.content,i.index)){let n=t.content[i.index];t.content[i.index]=c(this,K,`m`,ga).call(this,i,n,e)}else qi(t.content,i.index,i),n.push(i);i()}return[t,n]}case`thread.message.in_progress`:case`thread.message.completed`:case`thread.message.incomplete`:if(t)return[t,n];throw Error(`Received thread message event with no existing snapshot`)}throw Error(`Tried to accumulate a non-message event`)},ga=function(e,t,n){return Qi(t,e,n)},_a=function(e){switch(s(this,sa,e.data,`f`),e.event){case`thread.run.created`:break;case`thread.run.queued`:break;case`thread.run.in_progress`:break;case`thread.run.requires_action`:case`thread.run.cancelled`:case`thread.run.failed`:case`thread.run.completed`:case`thread.run.expired`:case`thread.run.incomplete`:s(this,na,e.data,`f`),c(this,Y,`f`)&&c(this,K,`m`,X).call(this,`toolCallDone`,c(this,Y,`f`)),s(this,aa,void 0,`f`),s(this,Y,void 0,`f`)}};var ya=class extends F{constructor(){super(...arguments),this.steps=new ji(this._client)}create(e,t,n){let{include:r,...i}=t;return this._client.post(I`/threads/${e}/runs`,{query:{include:r},body:i,...n,headers:N([{"OpenAI-Beta":`assistants=v2`},n?.headers]),stream:t.stream??!1,__synthesizeEventData:!0,__security:{bearerAuth:!0}})}retrieve(e,t,n){let{thread_id:r}=t;return this._client.get(I`/threads/${r}/runs/${e}`,{...n,headers:N([{"OpenAI-Beta":`assistants=v2`},n?.headers]),__security:{bearerAuth:!0}})}update(e,t,n){let{thread_id:r,...i}=t;return this._client.post(I`/threads/${r}/runs/${e}`,{body:i,...n,headers:N([{"OpenAI-Beta":`assistants=v2`},n?.headers]),__security:{bearerAuth:!0}})}list(e,t={},n){return this._client.getAPIList(I`/threads/${e}/runs`,j,{query:t,...n,headers:N([{"OpenAI-Beta":`assistants=v2`},n?.headers]),__security:{bearerAuth:!0}})}cancel(e,t,n){let{thread_id:r}=t;return this._client.post(I`/threads/${r}/runs/${e}/cancel`,{...n,headers:N([{"OpenAI-Beta":`assistants=v2`},n?.headers]),__security:{bearerAuth:!0}})}async createAndPoll(e,t,n){let r=await this.create(e,t,n);return await this.poll(r.id,{thread_id:e},n)}createAndStream(e,t,n){return va.createAssistantStream(e,this._client.beta.threads.runs,t,n)}async poll(e,t,n){let r=N([n?.headers,{"X-Stainless-Poll-Helper":`true`,"X-Stainless-Custom-Poll-Interval":n?.pollIntervalMs?.toString()??void 0}]);for(;;){let{data:i,response:a}=await this.retrieve(e,t,{...n,headers:{...n?.headers,...r}}).withResponse();switch(i.status){case`queued`:case`in_progress`:case`cancelling`:let e=5e3;if(n?.pollIntervalMs)e=n.pollIntervalMs;else{let t=a.headers.get(`openai-poll-after-ms`);if(t){let n=parseInt(t);isNaN(n)||(e=n)}}await ge(e);break;case`requires_action`:case`incomplete`:case`cancelled`:case`completed`:case`failed`:case`expired`:return i}}}stream(e,t,n){return va.createAssistantStream(e,this._client.beta.threads.runs,t,n)}submitToolOutputs(e,t,n){let{thread_id:r,...i}=t;return this._client.post(I`/threads/${r}/runs/${e}/submit_tool_outputs`,{body:i,...n,headers:N([{"OpenAI-Beta":`assistants=v2`},n?.headers]),stream:t.stream??!1,__synthesizeEventData:!0,__security:{bearerAuth:!0}})}async submitToolOutputsAndPoll(e,t,n){let r=await this.submitToolOutputs(e,t,n);return await this.poll(r.id,t,n)}submitToolOutputsStream(e,t,n){return va.createToolAssistantStream(e,this._client.beta.threads.runs,t,n)}};ya.Steps=ji;var ba=class extends F{constructor(){super(...arguments),this.runs=new ya(this._client),this.messages=new Ai(this._client)}create(e={},t){return this._client.post(`/threads`,{body:e,...t,headers:N([{"OpenAI-Beta":`assistants=v2`},t?.headers]),__security:{bearerAuth:!0}})}retrieve(e,t){return this._client.get(I`/threads/${e}`,{...t,headers:N([{"OpenAI-Beta":`assistants=v2`},t?.headers]),__security:{bearerAuth:!0}})}update(e,t,n){return this._client.post(I`/threads/${e}`,{body:t,...n,headers:N([{"OpenAI-Beta":`assistants=v2`},n?.headers]),__security:{bearerAuth:!0}})}delete(e,t){return this._client.delete(I`/threads/${e}`,{...t,headers:N([{"OpenAI-Beta":`assistants=v2`},t?.headers]),__security:{bearerAuth:!0}})}createAndRun(e,t){return this._client.post(`/threads/runs`,{body:e,...t,headers:N([{"OpenAI-Beta":`assistants=v2`},t?.headers]),stream:e.stream??!1,__synthesizeEventData:!0,__security:{bearerAuth:!0}})}async createAndRunPoll(e,t){let n=await this.createAndRun(e,t);return await this.runs.poll(n.id,{thread_id:n.thread_id},t)}createAndRunStream(e,t){return va.createThreadAssistantStream(e,this._client.beta.threads,t)}};ba.Runs=ya,ba.Messages=Ai;var xa=class extends F{constructor(){super(...arguments),this.realtime=new Ci(this._client),this.responses=new ki(this._client),this.chatkit=new Ei(this._client),this.assistants=new bi(this._client),this.threads=new ba(this._client)}};xa.Realtime=Ci,xa.Responses=ki,xa.ChatKit=Ei,xa.Assistants=bi,xa.Threads=ba;var Sa=class extends F{create(e,t){return this._client.post(`/completions`,{body:e,...t,stream:e.stream??!1,__security:{bearerAuth:!0}})}},Ca=class extends F{retrieve(e,t,n){let{container_id:r}=t;return this._client.get(I`/containers/${r}/files/${e}/content`,{...n,headers:N([{Accept:`application/binary`},n?.headers]),__security:{bearerAuth:!0},__binaryResponse:!0})}},wa=class extends F{constructor(){super(...arguments),this.content=new Ca(this._client)}create(e,t,n){return this._client.post(I`/containers/${e}/files`,Wt({body:t,...n,__security:{bearerAuth:!0}},this._client))}retrieve(e,t,n){let{container_id:r}=t;return this._client.get(I`/containers/${r}/files/${e}`,{...n,__security:{bearerAuth:!0}})}list(e,t={},n){return this._client.getAPIList(I`/containers/${e}/files`,j,{query:t,...n,__security:{bearerAuth:!0}})}delete(e,t,n){let{container_id:r}=t;return this._client.delete(I`/containers/${r}/files/${e}`,{...n,headers:N([{Accept:`*/*`},n?.headers]),__security:{bearerAuth:!0}})}};wa.Content=Ca;var Ta=class extends F{constructor(){super(...arguments),this.files=new wa(this._client)}create(e,t){return this._client.post(`/containers`,{body:e,...t,__security:{bearerAuth:!0}})}retrieve(e,t){return this._client.get(I`/containers/${e}`,{...t,__security:{bearerAuth:!0}})}list(e={},t){return this._client.getAPIList(`/containers`,j,{query:e,...t,__security:{bearerAuth:!0}})}delete(e,t){return this._client.delete(I`/containers/${e}`,{...t,headers:N([{Accept:`*/*`},t?.headers]),__security:{bearerAuth:!0}})}};Ta.Files=wa;var Ea=class extends F{create(e,t){return this._client.post(`/content_provenance_checks`,P({body:e,...t,__security:{bearerAuth:!0}},this._client))}},Da=class extends F{create(e,t,n){let{include:r,...i}=t;return this._client.post(I`/conversations/${e}/items`,{query:{include:r},body:i,...n,__security:{bearerAuth:!0}})}retrieve(e,t,n){let{conversation_id:r,...i}=t;return this._client.get(I`/conversations/${r}/items/${e}`,{query:i,...n,__security:{bearerAuth:!0}})}list(e,t={},n){return this._client.getAPIList(I`/conversations/${e}/items`,M,{query:t,...n,__security:{bearerAuth:!0}})}delete(e,t,n){let{conversation_id:r}=t;return this._client.delete(I`/conversations/${r}/items/${e}`,{...n,__security:{bearerAuth:!0}})}},Oa=class extends F{constructor(){super(...arguments),this.items=new Da(this._client)}create(e={},t){return this._client.post(`/conversations`,{body:e,...t,__security:{bearerAuth:!0}})}retrieve(e,t){return this._client.get(I`/conversations/${e}`,{...t,__security:{bearerAuth:!0}})}update(e,t,n){return this._client.post(I`/conversations/${e}`,{body:t,...n,__security:{bearerAuth:!0}})}delete(e,t){return this._client.delete(I`/conversations/${e}`,{...t,__security:{bearerAuth:!0}})}};Oa.Items=Da;var ka=class extends F{create(e,t){let n=!!e.encoding_format,r=n?e.encoding_format:`base64`;n&&k(this._client).debug(`embeddings/user defined encoding_format:`,e.encoding_format);let i=this._client.post(`/embeddings`,{body:{...e,encoding_format:r},...t,__security:{bearerAuth:!0}});return n?i:(k(this._client).debug(`embeddings/decoding base64 embeddings from base64`),i._thenUnwrap(e=>(e&&e.data&&e.data.forEach(e=>{let t=e.embedding;e.embedding=Ni(t)}),e)))}},Aa=class extends F{retrieve(e,t,n){let{eval_id:r,run_id:i}=t;return this._client.get(I`/evals/${r}/runs/${i}/output_items/${e}`,{...n,__security:{bearerAuth:!0}})}list(e,t,n){let{eval_id:r,...i}=t;return this._client.getAPIList(I`/evals/${r}/runs/${e}/output_items`,j,{query:i,...n,__security:{bearerAuth:!0}})}},ja=class extends F{constructor(){super(...arguments),this.outputItems=new Aa(this._client)}create(e,t,n){return this._client.post(I`/evals/${e}/runs`,{body:t,...n,__security:{bearerAuth:!0}})}retrieve(e,t,n){let{eval_id:r}=t;return this._client.get(I`/evals/${r}/runs/${e}`,{...n,__security:{bearerAuth:!0}})}list(e,t={},n){return this._client.getAPIList(I`/evals/${e}/runs`,j,{query:t,...n,__security:{bearerAuth:!0}})}delete(e,t,n){let{eval_id:r}=t;return this._client.delete(I`/evals/${r}/runs/${e}`,{...n,__security:{bearerAuth:!0}})}cancel(e,t,n){let{eval_id:r}=t;return this._client.post(I`/evals/${r}/runs/${e}`,{...n,__security:{bearerAuth:!0}})}};ja.OutputItems=Aa;var Ma=class extends F{constructor(){super(...arguments),this.runs=new ja(this._client)}create(e,t){return this._client.post(`/evals`,{body:e,...t,__security:{bearerAuth:!0}})}retrieve(e,t){return this._client.get(I`/evals/${e}`,{...t,__security:{bearerAuth:!0}})}update(e,t,n){return this._client.post(I`/evals/${e}`,{body:t,...n,__security:{bearerAuth:!0}})}list(e={},t){return this._client.getAPIList(`/evals`,j,{query:e,...t,__security:{bearerAuth:!0}})}delete(e,t){return this._client.delete(I`/evals/${e}`,{...t,__security:{bearerAuth:!0}})}};Ma.Runs=ja;var Na=class extends F{create(e,t){return this._client.post(`/files`,P({body:e,...t,__security:{bearerAuth:!0}},this._client))}retrieve(e,t){return this._client.get(I`/files/${e}`,{...t,__security:{bearerAuth:!0}})}list(e={},t){return this._client.getAPIList(`/files`,j,{query:e,...t,__security:{bearerAuth:!0}})}delete(e,t){return this._client.delete(I`/files/${e}`,{...t,__security:{bearerAuth:!0}})}content(e,t){return this._client.get(I`/files/${e}/content`,{...t,headers:N([{Accept:`application/binary`},t?.headers]),__security:{bearerAuth:!0},__binaryResponse:!0})}async waitForProcessing(e,{pollInterval:t=5e3,maxWait:n=18e5}={}){let r=new Set([`processed`,`error`,`deleted`]),i=Date.now(),a=await this.retrieve(e);for(;!a.status||!r.has(a.status);)if(await ge(t),a=await this.retrieve(e),Date.now()-i>n)throw new g({message:`Giving up on waiting for file ${e} to finish processing after ${n} milliseconds.`});return a}},Pa=class extends F{},Fa=class extends F{run(e,t){return this._client.post(`/fine_tuning/alpha/graders/run`,{body:e,...t,__security:{bearerAuth:!0}})}validate(e,t){return this._client.post(`/fine_tuning/alpha/graders/validate`,{body:e,...t,__security:{bearerAuth:!0}})}},Ia=class extends F{constructor(){super(...arguments),this.graders=new Fa(this._client)}};Ia.Graders=Fa;var La=class extends F{create(e,t,n){return this._client.getAPIList(I`/fine_tuning/checkpoints/${e}/permissions`,kt,{body:t,method:`post`,...n,__security:{adminAPIKeyAuth:!0}})}retrieve(e,t={},n){return this._client.get(I`/fine_tuning/checkpoints/${e}/permissions`,{query:t,...n,__security:{adminAPIKeyAuth:!0}})}list(e,t={},n){return this._client.getAPIList(I`/fine_tuning/checkpoints/${e}/permissions`,M,{query:t,...n,__security:{adminAPIKeyAuth:!0}})}delete(e,t,n){let{fine_tuned_model_checkpoint:r}=t;return this._client.delete(I`/fine_tuning/checkpoints/${r}/permissions/${e}`,{...n,__security:{adminAPIKeyAuth:!0}})}},Ra=class extends F{constructor(){super(...arguments),this.permissions=new La(this._client)}};Ra.Permissions=La;var za=class extends F{list(e,t={},n){return this._client.getAPIList(I`/fine_tuning/jobs/${e}/checkpoints`,j,{query:t,...n,__security:{bearerAuth:!0}})}},Ba=class extends F{constructor(){super(...arguments),this.checkpoints=new za(this._client)}create(e,t){return this._client.post(`/fine_tuning/jobs`,{body:e,...t,__security:{bearerAuth:!0}})}retrieve(e,t){return this._client.get(I`/fine_tuning/jobs/${e}`,{...t,__security:{bearerAuth:!0}})}list(e={},t){return this._client.getAPIList(`/fine_tuning/jobs`,j,{query:e,...t,__security:{bearerAuth:!0}})}cancel(e,t){return this._client.post(I`/fine_tuning/jobs/${e}/cancel`,{...t,__security:{bearerAuth:!0}})}listEvents(e,t={},n){return this._client.getAPIList(I`/fine_tuning/jobs/${e}/events`,j,{query:t,...n,__security:{bearerAuth:!0}})}pause(e,t){return this._client.post(I`/fine_tuning/jobs/${e}/pause`,{...t,__security:{bearerAuth:!0}})}resume(e,t){return this._client.post(I`/fine_tuning/jobs/${e}/resume`,{...t,__security:{bearerAuth:!0}})}};Ba.Checkpoints=za;var Va=class extends F{constructor(){super(...arguments),this.methods=new Pa(this._client),this.jobs=new Ba(this._client),this.checkpoints=new Ra(this._client),this.alpha=new Ia(this._client)}};Va.Methods=Pa,Va.Jobs=Ba,Va.Checkpoints=Ra,Va.Alpha=Ia;var Ha=class extends F{},Ua=class extends F{constructor(){super(...arguments),this.graderModels=new Ha(this._client)}};Ua.GraderModels=Ha;var Wa=class extends F{createVariation(e,t){return this._client.post(`/images/variations`,P({body:e,...t,__security:{bearerAuth:!0}},this._client))}edit(e,t){return this._client.post(`/images/edits`,P({body:e,...t,stream:e.stream??!1,__metadata:{...t?.__metadata,...e.model==null?{}:{model:e.model}},__security:{bearerAuth:!0}},this._client))}generate(e,t){return this._client.post(`/images/generations`,{body:e,...t,stream:e.stream??!1,__security:{bearerAuth:!0}})}},Ga=class extends F{retrieve(e,t){return this._client.get(I`/models/${e}`,{...t,__security:{bearerAuth:!0}})}list(e){return this._client.getAPIList(`/models`,kt,{...e,__security:{bearerAuth:!0}})}delete(e,t){return this._client.delete(I`/models/${e}`,{...t,__security:{bearerAuth:!0}})}},Ka=class extends F{create(e,t){return this._client.post(`/moderations`,{body:e,...t,__security:{bearerAuth:!0}})}},qa=class extends F{accept(e,t,n){return this._client.post(I`/realtime/calls/${e}/accept`,{body:t,...n,headers:N([{Accept:`*/*`},n?.headers]),__security:{bearerAuth:!0}})}hangup(e,t){return this._client.post(I`/realtime/calls/${e}/hangup`,{...t,headers:N([{Accept:`*/*`},t?.headers]),__security:{bearerAuth:!0}})}refer(e,t,n){return this._client.post(I`/realtime/calls/${e}/refer`,{body:t,...n,headers:N([{Accept:`*/*`},n?.headers]),__security:{bearerAuth:!0}})}reject(e,t={},n){return this._client.post(I`/realtime/calls/${e}/reject`,{body:t,...n,headers:N([{Accept:`*/*`},n?.headers]),__security:{bearerAuth:!0}})}},Ja=class extends F{create(e,t){return this._client.post(`/realtime/client_secrets`,{body:e,...t,__security:{bearerAuth:!0}})}},Ya=class extends F{constructor(){super(...arguments),this.clientSecrets=new Ja(this._client),this.calls=new qa(this._client)}};Ya.ClientSecrets=Ja,Ya.Calls=qa;function Xa(e,t){if(!t||!$a(t)){let t={...e,output_parsed:null,output:e.output.map(e=>e.type===`function_call`?{...e,parsed_arguments:null}:e.type===`message`?{...e,content:e.content.map(e=>({...e,parsed:null}))}:e)};return ro(e,t)&&io(t),t}return Za(e,t)}function Za(e,t){let n=!e.status||e.status===`completed`,r=e.output.map(e=>{if(e.type===`function_call`)return n?no(t,e):{...e,parsed_arguments:null};if(e.type===`message`){let r=e.content.map(e=>e.type===`output_text`?{...e,parsed:n?Qa(t,e.text):null}:e);return{...e,content:r}}return e}),i={...e,output:r};return ro(e,i)&&io(i),Object.defineProperty(i,"output_parsed",{enumerable:!0,get(){for(let e of i.output)if(e.type===`message`){for(let t of e.content)if(t.type===`output_text`&&t.parsed!==null)return t.parsed}return null}}),i}function Qa(e,t){return En(e.text?.format,t)}function $a(e){return Tn(e.text?.format)?!0:Array.isArray(e.tools)&&e.tools.some(e=>eo(e)||e.type===`function`&&e.strict===!0)}function eo(e){return e?.$brand===`auto-parseable-tool`}function to(e,t){return e.find(e=>e.type===`function`&&e.name===t)}function no(e,t){let n=to(e.tools??[],t.name),r=null;return eo(n)?r=n.$parseRaw(t.arguments):n?.strict&&(r=JSON.parse(t.arguments)),{...t,parsed_arguments:r}}function ro(e,t){return!Object.getOwnPropertyDescriptor(e,`output_text`)||t.output_text==null}function io(e){let t=[];for(let n of e.output)if(n.type===`message`)for(let e of n.content)e.type===`output_text`&&t.push(e.text);e.output_text=t.join(``)}var ao=class{constructor(){this.capacity=1,this.values=[0,0],this.size=0}get length(){return this.size}append(e){this.size===this.capacity&&this.grow();let t=this.size;this.size+=1,this.update(t,e)}update(e,t){if(!Number.isSafeInteger(e)||e<0||e>=this.size)throw RangeError(`missing output at index ${e}`);let n=this.capacity+e,r=t-(this.values[n]??0);if(r!==0)for(;n>=1;)this.values[n]=(this.values[n]??0)+r,n=Math.floor(n/2)}prefixSum(e){if(!Number.isSafeInteger(e)||e<0||e>this.size)throw RangeError(`missing output at index ${e}`);let t=this.capacity,n=this.capacity+e,r=0;for(;t<n;)t%2==1&&(r+=this.values[t]??0,t+=1),n%2==1&&(--n,r+=this.values[n]??0),t=Math.floor(t/2),n=Math.floor(n/2);return r}grow(){let e=this.capacity;this.capacity*=2;let t=Array.from({length:this.capacity*2},()=>0);for(let n=0;n<this.size;n+=1)t[this.capacity+n]=this.values[e+n]??0;for(let e=this.capacity-1;e>0;--e)t[e]=(t[e*2]??0)+(t[e*2+1]??0);this.values=t}};function oo(){return{canonicalSnapshot:void 0,outputTextLengths:new WeakMap,outputTextIndex:new ao}}function so(e,t){if(t.type!==`message`)return``;let n=``;for(let e of t.content)e.type===`output_text`&&(n+=e.text);return e.outputTextLengths.set(t,n.length),n}function co(e,t){if(e.canonicalSnapshot===t)return;let n=new ao,r=``;for(let i of t.output){let t=so(e,i);r+=t,n.append(t.length)}t.output_text!==r&&(t.output_text=r),e.outputTextIndex=n,e.canonicalSnapshot=t}function lo(e,t){e.canonicalSnapshot=void 0,e.outputTextLengths=new WeakMap,e.outputTextIndex=new ao;let n=structuredClone(t);return!Object.getOwnPropertyDescriptor(n,`output_text`)||n.output_text===null||n.output_text===void 0?co(e,n):n.output.length===0&&n.output_text===``&&(e.canonicalSnapshot=n),n}function uo(e,t,n,r,i){let a=e.outputTextLengths.get(t);if(a!==void 0){let o=a-r.length+i.length;e.outputTextLengths.set(t,o),e.outputTextIndex.update(n,o)}}function fo(e,t,n){if(t.length===0){e.output_text+=n;return}e.output_text=e.output_text.slice(0,e.output_text.length-t.length)+n}function po(e,t,n,r){if(n===void 0||t?.type!==`message`)return 0;if(n<t.content.length-n-1){let e=0;for(let r=0;r<n;r+=1){let n=t.content[r];n?.type===`output_text`&&(e+=n.text.length)}return e}let i=0;for(let e=n+1;e<t.content.length;e+=1){let n=t.content[e];n?.type===`output_text`&&(i+=n.text.length)}return(e.outputTextLengths.get(t)??so(e,t).length)-i-r.length}function mo(e,t,n,r,i,a){if(r===i)return;let o=t.output[n];if(n===t.output.length-1&&(a===void 0||o?.type===`message`&&a===o.content.length-1)){fo(t,r,i);return}let s=po(e,o,a,i),c=e.outputTextIndex.prefixSum(n)+s;if(c+r.length===t.output_text.length){fo(t,r,i);return}t.output_text=t.output_text.slice(0,c)+i+t.output_text.slice(c+r.length)}function ho(e,t,n,r=!1){if(!Number.isSafeInteger(t)||t<0||t>e.length||(t===e.length?!r||t in e:!pe(e,t)))throw new f(`missing ${n} at index ${t}`)}function go(e,t,n){if(t!==e.length)throw new f(`missing ${n} at index ${t}`);ho(e,t,n,!0)}function Z(e,t){ho(e.output,t,`output`);let n=e.output[t];if(!n)throw new f(`missing output at index ${t}`);return n}function Q(e,t){ho(e,t,`content`);let n=e[t];if(!n)throw new f(`missing content at index ${t}`);return n}function _o(e,t,n){let r=e.output.find(e=>e.type===`shell_call`&&e.call_id===t.call_id);for(r?ho(r.action.commands,n,`command`):ho(t.output,n,`content`,!0);t.output.length<=n;)t.output.push({stdout:``,stderr:``,outcome:{type:`exit`,exit_code:0}});return Q(t.output,n)}function vo(e){throw new f(`Unhandled response stream event: ${JSON.stringify(e)}`)}function yo(e,t,n){switch(e.type){case`response.output_item.added`:{go(t.output,e.output_index,`output`);let r=structuredClone(e.item);r.type===`message`&&co(n,t),t.output.push(r);let i=so(n,r);return n.canonicalSnapshot===t&&n.outputTextIndex.append(i.length),i&&(t.output_text+=i),!0}case`response.output_item.done`:{let r=Z(t,e.output_index),i=so(n,r),a=structuredClone(e.item);(r.type===`message`||a.type===`message`)&&co(n,t),t.output[e.output_index]=a;let o=so(n,a);return n.canonicalSnapshot===t&&n.outputTextIndex.update(e.output_index,o.length),mo(n,t,e.output_index,i,o),!0}default:return!1}}function bo(e,t,n){switch(e.type){case`response.content_part.added`:{let r=Z(t,e.output_index),{type:i}=r,{part:a}=e;if(i===`message`&&a.type!==`reasoning_text`){go(r.content,e.content_index,`content`);let i=structuredClone(a);i.type===`output_text`&&co(n,t),r.content.push(i),i.type===`output_text`&&(uo(n,r,e.output_index,``,i.text),mo(n,t,e.output_index,``,i.text,e.content_index))}else if(i===`reasoning`&&a.type===`reasoning_text`){let t=r.content??[];go(t,e.content_index,`content`),r.content||=t,t.push(structuredClone(a))}return!0}default:return!1}}function xo(e,t,n){switch(e.type){case`response.content_part.done`:{let r=Z(t,e.output_index),{part:i}=e;if(r.type===`message`&&i.type!==`reasoning_text`){let a=Q(r.content,e.content_index),o=a.type===`output_text`?a.text:``,s=structuredClone(i);(a.type===`output_text`||s.type===`output_text`)&&co(n,t),r.content[e.content_index]=s;let c=s.type===`output_text`?s.text:``;uo(n,r,e.output_index,o,c),mo(n,t,e.output_index,o,c,e.content_index)}else if(r.type===`reasoning`&&i.type===`reasoning_text`){let{content:t}=r;if(!t)throw new f(`missing content at index ${e.content_index}`);Q(t,e.content_index),t[e.content_index]=structuredClone(i)}return!0}default:return!1}}function So(e,t,n){switch(e.type){case`response.output_text.delta`:{let r=Z(t,e.output_index);if(r.type===`message`){let i=Q(r.content,e.content_index);if(i.type!==`output_text`)throw new f(`expected content to be 'output_text', got ${i.type}`);let a=i.text;co(n,t),i.text=a+e.delta,uo(n,r,e.output_index,a,i.text),e.output_index===t.output.length-1&&e.content_index===r.content.length-1?t.output_text+=e.delta:mo(n,t,e.output_index,a,i.text,e.content_index)}return!0}case`response.output_text.done`:{let r=Z(t,e.output_index);if(r.type===`message`){let i=Q(r.content,e.content_index);if(i.type!==`output_text`)throw new f(`expected content to be 'output_text', got ${i.type}`);let a=i.text;co(n,t),i.text=e.text,uo(n,r,e.output_index,a,e.text),mo(n,t,e.output_index,a,e.text,e.content_index)}return!0}case`response.output_text.annotation.added`:{let n=Z(t,e.output_index);if(n.type===`message`){let t=Q(n.content,e.content_index);if(t.type!==`output_text`)throw new f(`expected content to be 'output_text', got ${t.type}`);ho(t.annotations,e.annotation_index,`annotation`,!0),t.annotations[e.annotation_index]=structuredClone(e.annotation)}return!0}default:return!1}}function Co(e,t){switch(e.type){case`response.refusal.delta`:{let n=Z(t,e.output_index);if(n.type===`message`){let t=Q(n.content,e.content_index);if(t.type!==`refusal`)throw new f(`expected content to be 'refusal', got ${t.type}`);t.refusal+=e.delta}return!0}case`response.refusal.done`:{let n=Z(t,e.output_index);if(n.type===`message`){let t=Q(n.content,e.content_index);if(t.type!==`refusal`)throw new f(`expected content to be 'refusal', got ${t.type}`);t.refusal=e.refusal}return!0}case`response.function_call_arguments.delta`:{let n=Z(t,e.output_index);return n.type===`function_call`&&(n.arguments+=e.delta),!0}case`response.function_call_arguments.done`:{let n=Z(t,e.output_index);return n.type===`function_call`&&(n.arguments=e.arguments),!0}case`response.custom_tool_call_input.delta`:{let n=Z(t,e.output_index);return n.type===`custom_tool_call`&&(n.input+=e.delta),!0}case`response.custom_tool_call_input.done`:{let n=Z(t,e.output_index);return n.type===`custom_tool_call`&&(n.input=e.input),!0}case`response.mcp_call_arguments.delta`:{let n=Z(t,e.output_index);return n.type===`mcp_call`&&(n.arguments+=e.delta),!0}case`response.mcp_call_arguments.done`:{let n=Z(t,e.output_index);return n.type===`mcp_call`&&(n.arguments=e.arguments),!0}default:return!1}}function wo(e,t){switch(e.type){case`response.shell_call_command.added`:case`response.shell_call_command.done`:{let n=Z(t,e.output_index);if(n.type===`shell_call`){let t=e.type===`response.shell_call_command.added`;ho(n.action.commands,e.command_index,`command`,t),n.action.commands[e.command_index]=e.command}return!0}case`response.shell_call_command.delta`:{let n=Z(t,e.output_index);return n.type===`shell_call`&&(ho(n.action.commands,e.command_index,`command`),n.action.commands[e.command_index]+=e.delta),!0}case`response.shell_call_output_content.delta`:{let n=Z(t,e.output_index);if(n.type===`shell_call_output`){let r=_o(t,n,e.command_index);r.stdout+=e.delta.stdout??``,r.stderr+=e.delta.stderr??``}return!0}case`response.shell_call_output_content.done`:{let n=Z(t,e.output_index);if(n.type===`shell_call_output`){let r=Q(e.output,0);_o(t,n,e.command_index),n.output[e.command_index]=structuredClone(r)}return!0}default:return!1}}function To(e,t){switch(e.type){case`response.reasoning_text.delta`:{let n=Z(t,e.output_index);if(n.type===`reasoning`){if(!n.content)throw new f(`missing content at index ${e.content_index}`);let t=Q(n.content,e.content_index);if(t.type!==`reasoning_text`)throw new f(`expected content to be 'reasoning_text', got ${t.type}`);t.text+=e.delta}return!0}case`response.reasoning_text.done`:{let n=Z(t,e.output_index);if(n.type===`reasoning`){if(!n.content)throw new f(`missing content at index ${e.content_index}`);let t=Q(n.content,e.content_index);if(t.type!==`reasoning_text`)throw new f(`expected content to be 'reasoning_text', got ${t.type}`);t.text=e.text}return!0}case`response.reasoning_summary_part.added`:{let n=Z(t,e.output_index);return n.type===`reasoning`&&(go(n.summary,e.summary_index,`content`),n.summary.push(structuredClone(e.part))),!0}case`response.reasoning_summary_part.done`:{let n=Z(t,e.output_index);return n.type===`reasoning`&&(Q(n.summary,e.summary_index),n.summary[e.summary_index]=structuredClone(e.part)),!0}case`response.reasoning_summary_text.delta`:{let n=Z(t,e.output_index);if(n.type===`reasoning`){let t=Q(n.summary,e.summary_index);t.text+=e.delta}return!0}case`response.reasoning_summary_text.done`:{let n=Z(t,e.output_index);if(n.type===`reasoning`){let t=Q(n.summary,e.summary_index);t.text=e.text}return!0}default:return!1}}function Eo(e,t){switch(e.type){case`response.code_interpreter_call_code.delta`:{let n=Z(t,e.output_index);return n.type===`code_interpreter_call`&&(n.code=(n.code??``)+e.delta),!0}case`response.code_interpreter_call_code.done`:{let n=Z(t,e.output_index);return n.type===`code_interpreter_call`&&(n.code=e.code),!0}case`response.code_interpreter_call.in_progress`:{let n=Z(t,e.output_index);return n.type===`code_interpreter_call`&&(n.status=`in_progress`),!0}case`response.code_interpreter_call.interpreting`:{let n=Z(t,e.output_index);return n.type===`code_interpreter_call`&&(n.status=`interpreting`),!0}case`response.code_interpreter_call.completed`:{let n=Z(t,e.output_index);return n.type===`code_interpreter_call`&&(n.status=`completed`),!0}default:return!1}}function Do(e,t){switch(e.type){case`response.file_search_call.in_progress`:{let n=Z(t,e.output_index);return n.type===`file_search_call`&&(n.status=`in_progress`),!0}case`response.file_search_call.searching`:{let n=Z(t,e.output_index);return n.type===`file_search_call`&&(n.status=`searching`),!0}case`response.file_search_call.completed`:{let n=Z(t,e.output_index);return n.type===`file_search_call`&&(n.status=`completed`),!0}case`response.web_search_call.in_progress`:{let n=Z(t,e.output_index);return n.type===`web_search_call`&&(n.status=`in_progress`),!0}case`response.web_search_call.searching`:{let n=Z(t,e.output_index);return n.type===`web_search_call`&&(n.status=`searching`),!0}case`response.web_search_call.completed`:{let n=Z(t,e.output_index);return n.type===`web_search_call`&&(n.status=`completed`),!0}default:return!1}}function Oo(e,t){switch(e.type){case`response.image_generation_call.in_progress`:{let n=Z(t,e.output_index);return n.type===`image_generation_call`&&(n.status=`in_progress`),!0}case`response.image_generation_call.generating`:{let n=Z(t,e.output_index);return n.type===`image_generation_call`&&(n.status=`generating`),!0}case`response.image_generation_call.completed`:{let n=Z(t,e.output_index);return n.type===`image_generation_call`&&(n.status=`completed`),!0}case`response.mcp_call.in_progress`:{let n=Z(t,e.output_index);return n.type===`mcp_call`&&(n.status=`in_progress`),!0}case`response.mcp_call.completed`:{let n=Z(t,e.output_index);return n.type===`mcp_call`&&(n.status=`completed`),!0}case`response.mcp_call.failed`:{let n=Z(t,e.output_index);return n.type===`mcp_call`&&(n.status=`failed`),!0}default:return!1}}function ko(e){switch(e.type){case`response.created`:case`response.queued`:case`response.in_progress`:case`response.completed`:case`response.failed`:case`response.incomplete`:return!0;default:return!1}}function Ao(e){switch(e.type){case`response.audio.delta`:case`response.audio.done`:case`response.audio.transcript.delta`:case`response.audio.transcript.done`:case`response.image_generation_call.partial_image`:case`response.mcp_list_tools.in_progress`:case`response.mcp_list_tools.completed`:case`response.mcp_list_tools.failed`:case`keepalive`:case`error`:return!0;default:return!1}}function jo(){return oo()}function Mo(e,t,n){if(!t){if(e.type!==`response.created`)throw new f(`When snapshot hasn't been set yet, expected 'response.created' event, got ${e.type}`);return lo(n,e.response)}return yo(e,t,n)||bo(e,t,n)||xo(e,t,n)||So(e,t,n)||Co(e,t)||wo(e,t)||To(e,t)||Eo(e,t)||Do(e,t)||Oo(e,t)?t:ko(e)?lo(n,e.response):Ao(e)?t:vo(e)}var No,Po,Fo,Io,Lo,Ro,zo,Bo,Vo=class e extends $n{constructor(e){super(),No.add(this),Po.set(this,void 0),Fo.set(this,void 0),Io.set(this,void 0),Lo.set(this,jo()),s(this,Po,e,`f`)}static createResponse(t,n,r){let i=new e(n);return i._run(()=>i._createOrRetrieveResponse(t,n,{...r,__metadata:{...r?.__metadata,helperMethod:`stream`}})),i}static fromReadableStream(t){let n=new e(null);return n._run(()=>n._fromReadableStream(t)),n}async _createOrRetrieveResponse(e,t,n){this._listenForAbort(n?.signal),c(this,No,`m`,Ro).call(this);let r,i=null;`response_id`in t?(r=await e.responses.retrieve(t.response_id,{stream:!0},{...n,signal:this.controller.signal,stream:!0}),i=t.starting_after??null):r=await e.responses.create({...t,stream:!0},{...n,signal:this.controller.signal}),this._connected();for await(let e of r)c(this,No,`m`,zo).call(this,e,i);if(r.controller.signal?.aborted)throw new m;return c(this,No,`m`,Bo).call(this)}async _fromReadableStream(e,t){this._listenForAbort(t?.signal),c(this,No,`m`,Ro).call(this),this._connected();let n=Ve.fromReadableStream(e,this.controller);for await(let e of n)c(this,No,`m`,zo).call(this,e,null);if(n.controller.signal?.aborted)throw new m;return c(this,No,`m`,Bo).call(this)}[(Po=new WeakMap,Fo=new WeakMap,Io=new WeakMap,Lo=new WeakMap,No=new WeakSet,Ro=function(){this.ended||(s(this,Fo,void 0,`f`),s(this,Lo,jo(),`f`))},zo=function(e,t){if(this.ended)return;let n=(e,n)=>{(t==null||n.sequence_number>t)&&this._emit(e,n)};if(e.type===`error`)throw new p(void 0,`error`in e&&typeof e.error==`object`&&e.error!==null?e.error:e,e.message,void 0);let r=Mo(e,c(this,Fo,`f`),c(this,Lo,`f`));switch(s(this,Fo,r,`f`),n(`event`,e),e.type){case`response.output_text.delta`:{let t=r.output[e.output_index];if(!t)throw new f(`missing output at index ${e.output_index}`);if(t.type===`message`){let r=t.content[e.content_index];if(!r)throw new f(`missing content at index ${e.content_index}`);if(r.type!==`output_text`)throw new f(`expected content to be 'output_text', got ${r.type}`);n(`response.output_text.delta`,{...e,snapshot:r.text})}break}case`response.function_call_arguments.delta`:{let t=r.output[e.output_index];if(!t)throw new f(`missing output at index ${e.output_index}`);t.type===`function_call`&&n(`response.function_call_arguments.delta`,{...e,snapshot:t.arguments});break}default:n(e.type,e)}},Bo=function(){if(this.ended)throw new f(`stream has ended, this shouldn't happen`);let e=c(this,Fo,`f`);if(!e)throw new f(`request ended without sending any events`);s(this,Fo,void 0,`f`),s(this,Lo,jo(),`f`);let t=Ho(e,c(this,Po,`f`));return s(this,Io,t,`f`),t},Symbol.asyncIterator)](){return this._createIterator(e=>{let t=t=>e(t);return this.on(`event`,t),()=>this.off(`event`,t)},{onReturn:()=>this.abort()})}async finalResponse(){await this.done();let e=c(this,Io,`f`);if(!e)throw new f(`stream ended without producing a Response`);return e}};function Ho(e,t){return Xa(e,t)}var Uo=class extends F{list(e,t={},n){return this._client.getAPIList(I`/responses/${e}/input_items`,j,{query:t,...n,__security:{bearerAuth:!0}})}},Wo=class extends F{count(e={},t){return this._client.post(`/responses/input_tokens`,{body:e,...t,__security:{bearerAuth:!0}})}},Go=class extends F{constructor(){super(...arguments),this.inputItems=new Uo(this._client),this.inputTokens=new Wo(this._client)}create(e,t){return this._client.post(`/responses`,{body:e,...t,stream:e.stream??!1,__security:{bearerAuth:!0}})._thenUnwrap(e=>(`object`in e&&e.object===`response`&&io(e),e))}retrieve(e,t={},n){return this._client.get(I`/responses/${e}`,{query:t,...n,stream:t?.stream??!1,__security:{bearerAuth:!0}})._thenUnwrap(e=>(`object`in e&&e.object===`response`&&io(e),e))}delete(e,t){return this._client.delete(I`/responses/${e}`,{...t,headers:N([{Accept:`*/*`},t?.headers]),__security:{bearerAuth:!0}})}parse(e,t){return this._client.responses.create(e,t)._thenUnwrap(t=>Za(t,e))}stream(e,t){return Vo.createResponse(this._client,e,t)}cancel(e,t){return this._client.post(I`/responses/${e}/cancel`,{...t,__security:{bearerAuth:!0}})}compact(e,t){return this._client.post(`/responses/compact`,{body:e,...t,__security:{bearerAuth:!0}})}};Go.InputItems=Uo,Go.InputTokens=Wo;var Ko=class extends F{retrieve(e,t){return this._client.get(I`/skills/${e}/content`,{...t,headers:N([{Accept:`application/binary`},t?.headers]),__security:{bearerAuth:!0},__binaryResponse:!0})}},qo=class extends F{retrieve(e,t,n){let{skill_id:r}=t;return this._client.get(I`/skills/${r}/versions/${e}/content`,{...n,headers:N([{Accept:`application/binary`},n?.headers]),__security:{bearerAuth:!0},__binaryResponse:!0})}},Jo=class extends F{constructor(){super(...arguments),this.content=new qo(this._client)}create(e,t={},n){return this._client.post(I`/skills/${e}/versions`,Wt({body:t,...n,__security:{bearerAuth:!0}},this._client,{stripFilenames:!1}))}retrieve(e,t,n){let{skill_id:r}=t;return this._client.get(I`/skills/${r}/versions/${e}`,{...n,__security:{bearerAuth:!0}})}list(e,t={},n){return this._client.getAPIList(I`/skills/${e}/versions`,j,{query:t,...n,__security:{bearerAuth:!0}})}delete(e,t,n){let{skill_id:r}=t;return this._client.delete(I`/skills/${r}/versions/${e}`,{...n,__security:{bearerAuth:!0}})}};Jo.Content=qo;var Yo=class extends F{constructor(){super(...arguments),this.content=new Ko(this._client),this.versions=new Jo(this._client)}create(e={},t){return this._client.post(`/skills`,Wt({body:e,...t,__security:{bearerAuth:!0}},this._client,{stripFilenames:!1}))}retrieve(e,t){return this._client.get(I`/skills/${e}`,{...t,__security:{bearerAuth:!0}})}update(e,t,n){return this._client.post(I`/skills/${e}`,{body:t,...n,__security:{bearerAuth:!0}})}list(e={},t){return this._client.getAPIList(`/skills`,j,{query:e,...t,__security:{bearerAuth:!0}})}delete(e,t){return this._client.delete(I`/skills/${e}`,{...t,__security:{bearerAuth:!0}})}};Yo.Content=Ko,Yo.Versions=Jo;var Xo=class extends F{create(e,t,n){return this._client.post(I`/uploads/${e}/parts`,P({body:t,...n,__security:{bearerAuth:!0}},this._client))}},Zo=class extends F{constructor(){super(...arguments),this.parts=new Xo(this._client)}create(e,t){return this._client.post(`/uploads`,{body:e,...t,__security:{bearerAuth:!0}})}cancel(e,t){return this._client.post(I`/uploads/${e}/cancel`,{...t,__security:{bearerAuth:!0}})}complete(e,t,n){return this._client.post(I`/uploads/${e}/complete`,{body:t,...n,__security:{bearerAuth:!0}})}};Zo.Parts=Xo;const Qo=async e=>{let t=await Promise.allSettled(e),n=t.filter(e=>e.status===`rejected`);if(n.length){for(let e of n)console.error(e.reason);throw Error(`${n.length} promise(s) failed - see the above errors`)}let r=[];for(let e of t)e.status===`fulfilled`&&r.push(e.value);return r};var $o=class extends F{create(e,t,n){return this._client.post(I`/vector_stores/${e}/file_batches`,{body:t,...n,headers:N([{"OpenAI-Beta":`assistants=v2`},n?.headers]),__security:{bearerAuth:!0}})}retrieve(e,t,n){let{vector_store_id:r}=t;return this._client.get(I`/vector_stores/${r}/file_batches/${e}`,{...n,headers:N([{"OpenAI-Beta":`assistants=v2`},n?.headers]),__security:{bearerAuth:!0}})}cancel(e,t,n){let{vector_store_id:r}=t;return this._client.post(I`/vector_stores/${r}/file_batches/${e}/cancel`,{...n,headers:N([{"OpenAI-Beta":`assistants=v2`},n?.headers]),__security:{bearerAuth:!0}})}async createAndPoll(e,t,n){let r=await this.create(e,t,n);return await this.poll(e,r.id,n)}listFiles(e,t,n){let{vector_store_id:r,...i}=t;return this._client.getAPIList(I`/vector_stores/${r}/file_batches/${e}/files`,j,{query:i,...n,headers:N([{"OpenAI-Beta":`assistants=v2`},n?.headers]),__security:{bearerAuth:!0}})}async poll(e,t,n){let r=N([n?.headers,{"X-Stainless-Poll-Helper":`true`,"X-Stainless-Custom-Poll-Interval":n?.pollIntervalMs?.toString()??void 0}]);for(;;){let{data:i,response:a}=await this.retrieve(t,{vector_store_id:e},{...n,headers:r}).withResponse();switch(i.status){case`in_progress`:let e=5e3;if(n?.pollIntervalMs)e=n.pollIntervalMs;else{let t=a.headers.get(`openai-poll-after-ms`);if(t){let n=parseInt(t);isNaN(n)||(e=n)}}await ge(e);break;case`failed`:case`cancelled`:case`completed`:return i}}}async uploadAndPoll(e,{files:t,fileIds:n=[]},r){if(t==null||t.length==0)throw Error("No `files` provided to process. If you've already uploaded files you should use `.createAndPoll()` instead");let i=r?.maxConcurrency??5,a=Math.min(i,t.length),o=this._client,s=t.values(),c=[...n];async function l(e){for(let t of e){let e=await o.files.create({file:t,purpose:`assistants`},r);c.push(e.id)}}let u=Array(a).fill(s).map(l);return await Qo(u),await this.createAndPoll(e,{file_ids:c},r)}},es=class extends F{create(e,t,n){return this._client.post(I`/vector_stores/${e}/files`,{body:t,...n,headers:N([{"OpenAI-Beta":`assistants=v2`},n?.headers]),__security:{bearerAuth:!0}})}retrieve(e,t,n){let{vector_store_id:r}=t;return this._client.get(I`/vector_stores/${r}/files/${e}`,{...n,headers:N([{"OpenAI-Beta":`assistants=v2`},n?.headers]),__security:{bearerAuth:!0}})}update(e,t,n){let{vector_store_id:r,...i}=t;return this._client.post(I`/vector_stores/${r}/files/${e}`,{body:i,...n,headers:N([{"OpenAI-Beta":`assistants=v2`},n?.headers]),__security:{bearerAuth:!0}})}list(e,t={},n){return this._client.getAPIList(I`/vector_stores/${e}/files`,j,{query:t,...n,headers:N([{"OpenAI-Beta":`assistants=v2`},n?.headers]),__security:{bearerAuth:!0}})}delete(e,t,n){let{vector_store_id:r}=t;return this._client.delete(I`/vector_stores/${r}/files/${e}`,{...n,headers:N([{"OpenAI-Beta":`assistants=v2`},n?.headers]),__security:{bearerAuth:!0}})}async createAndPoll(e,t,n){let r=await this.create(e,t,n);return await this.poll(e,r.id,n)}async poll(e,t,n){let r=N([n?.headers,{"X-Stainless-Poll-Helper":`true`,"X-Stainless-Custom-Poll-Interval":n?.pollIntervalMs?.toString()??void 0}]);for(;;){let i=await this.retrieve(t,{vector_store_id:e},{...n,headers:r}).withResponse(),a=i.data;switch(a.status){case`in_progress`:let e=5e3;if(n?.pollIntervalMs)e=n.pollIntervalMs;else{let t=i.response.headers.get(`openai-poll-after-ms`);if(t){let n=parseInt(t);isNaN(n)||(e=n)}}await ge(e);break;case`failed`:case`completed`:return a}}}async upload(e,t,n){let r=await this._client.files.create({file:t,purpose:`assistants`},n);return this.create(e,{file_id:r.id},n)}async uploadAndPoll(e,t,n){let r=await this.upload(e,t,n);return await this.poll(e,r.id,n)}content(e,t,n){let{vector_store_id:r}=t;return this._client.getAPIList(I`/vector_stores/${r}/files/${e}/content`,kt,{...n,headers:N([{"OpenAI-Beta":`assistants=v2`},n?.headers]),__security:{bearerAuth:!0}})}},ts=class extends F{constructor(){super(...arguments),this.files=new es(this._client),this.fileBatches=new $o(this._client)}create(e,t){return this._client.post(`/vector_stores`,{body:e,...t,headers:N([{"OpenAI-Beta":`assistants=v2`},t?.headers]),__security:{bearerAuth:!0}})}retrieve(e,t){return this._client.get(I`/vector_stores/${e}`,{...t,headers:N([{"OpenAI-Beta":`assistants=v2`},t?.headers]),__security:{bearerAuth:!0}})}update(e,t,n){return this._client.post(I`/vector_stores/${e}`,{body:t,...n,headers:N([{"OpenAI-Beta":`assistants=v2`},n?.headers]),__security:{bearerAuth:!0}})}list(e={},t){return this._client.getAPIList(`/vector_stores`,j,{query:e,...t,headers:N([{"OpenAI-Beta":`assistants=v2`},t?.headers]),__security:{bearerAuth:!0}})}delete(e,t){return this._client.delete(I`/vector_stores/${e}`,{...t,headers:N([{"OpenAI-Beta":`assistants=v2`},t?.headers]),__security:{bearerAuth:!0}})}search(e,t,n){return this._client.getAPIList(I`/vector_stores/${e}/search`,kt,{body:t,method:`post`,...n,headers:N([{"OpenAI-Beta":`assistants=v2`},n?.headers]),__security:{bearerAuth:!0}})}};ts.Files=es,ts.FileBatches=$o;var ns=class extends F{create(e,t){return this._client.post(`/videos`,P({body:e,...t,__security:{bearerAuth:!0}},this._client))}retrieve(e,t){return this._client.get(I`/videos/${e}`,{...t,__security:{bearerAuth:!0}})}list(e={},t){return this._client.getAPIList(`/videos`,M,{query:e,...t,__security:{bearerAuth:!0}})}delete(e,t){return this._client.delete(I`/videos/${e}`,{...t,__security:{bearerAuth:!0}})}createCharacter(e,t){return this._client.post(`/videos/characters`,P({body:e,...t,__security:{bearerAuth:!0}},this._client))}downloadContent(e,t={},n){return this._client.get(I`/videos/${e}/content`,{query:t,...n,headers:N([{Accept:`application/binary`},n?.headers]),__security:{bearerAuth:!0},__binaryResponse:!0})}edit(e,t){return this._client.post(`/videos/edits`,P({body:e,...t,__security:{bearerAuth:!0}},this._client))}extend(e,t){return this._client.post(`/videos/extensions`,P({body:e,...t,__security:{bearerAuth:!0}},this._client))}getCharacter(e,t){return this._client.get(I`/videos/characters/${e}`,{...t,__security:{bearerAuth:!0}})}remix(e,t,n){return this._client.post(I`/videos/${e}/remix`,Wt({body:t,...n,__security:{bearerAuth:!0}},this._client))}},rs,is,as,os=class extends F{constructor(){super(...arguments),rs.add(this)}async unwrap(e,t,n=this._client.webhookSecret,r=300){return await this.verifySignature(e,t,n,r),JSON.parse(e)}async verifySignature(e,t,n=this._client.webhookSecret,r=300){if(typeof crypto>`u`||typeof crypto.subtle.importKey!=`function`||typeof crypto.subtle.verify!=`function`)throw Error("Webhook signature verification is only supported when the `crypto` global is defined");c(this,rs,`m`,is).call(this,n);let i=N([t]).values,a=c(this,rs,`m`,as).call(this,i,`webhook-signature`),o=c(this,rs,`m`,as).call(this,i,`webhook-timestamp`),s=c(this,rs,`m`,as).call(this,i,`webhook-id`),l=parseInt(o,10);if(isNaN(l))throw new ae(`Invalid webhook timestamp format`);let u=Math.floor(Date.now()/1e3);if(u-l>r)throw new ae(`Webhook timestamp is too old`);if(l>u+r)throw new ae(`Webhook timestamp is too new`);let d=a.split(` `).map(e=>e.startsWith(`v1,`)?e.substring(3):e),f=Uint8Array.from(n.startsWith(`whsec_`)?Mi(n.slice(6)):w(n)),p=s?`${s}.${o}.${e}`:`${o}.${e}`,m=Uint8Array.from(w(p)),h=await crypto.subtle.importKey(`raw`,f,{name:`HMAC`,hash:`SHA-256`},!1,[`verify`]);for(let e of d)try{let t=Uint8Array.from(Mi(e));if(await crypto.subtle.verify(`HMAC`,h,t,m))return}catch{continue}throw new ae(`The given webhook signature does not match the expected signature`)}};rs=new WeakSet,is=function(e){if(typeof e!=`string`||e.length===0)throw Error(`The webhook secret must either be set using the env var, OPENAI_WEBHOOK_SECRET, on the client class, OpenAI({ webhookSecret: '123' }), or passed to this function`)},as=function(e,t){if(!e)throw Error(`Headers are required`);let n=e.get(t);if(n==null)throw Error(`Missing required header: ${t}`);return n};const ss=Symbol.for(`openai.node.providerDefinitions.v1`),cs=globalThis,ls=cs[ss],us=ls??new WeakMap;ls||Object.defineProperty(cs,ss,{value:us});function ds(e){let t=us.get(e);if(!t)throw Error(`Invalid provider. Providers must be created with createProvider().`);return t.configure()}var fs,ps,ms,hs,gs;function _s(){if(Xe())return!0;let e=globalThis;return typeof e.WorkerGlobalScope==`function`&&e instanceof e.WorkerGlobalScope&&typeof e.WorkerNavigator==`function`&&e.navigator instanceof e.WorkerNavigator&&typeof e.navigator?.userAgent==`string`&&e.navigator.userAgent!==`Cloudflare-Workers`&&e.process?.versions?.node===void 0&&e.Deno===void 0&&e.Bun===void 0&&e.EdgeRuntime===void 0&&e.WebSocketPair===void 0}var $=class{constructor(e={}){fs.add(this),ms.set(this,void 0),hs.set(this,new WeakMap),this.completions=new Sa(this),this.chat=new Rr(this),this.embeddings=new ka(this),this.files=new Na(this),this.images=new Wa(this),this.contentProvenanceChecks=new Ea(this),this.audio=new vi(this),this.moderations=new Ka(this),this.models=new Ga(this),this.fineTuning=new Va(this),this.graders=new Ua(this),this.vectorStores=new ts(this),this.webhooks=new os(this),this.beta=new xa(this),this.batches=new yi(this),this.uploads=new Zo(this),this.admin=new mi(this),this.responses=new Go(this),this.realtime=new Ya(this),this.conversations=new Oa(this),this.evals=new Ma(this),this.containers=new Ta(this),this.skills=new Yo(this),this.videos=new ns(this);let t=e.provider;if(t){let t=[`apiKey`,`adminAPIKey`,`workloadIdentity`,`baseURL`].filter(t=>e[t]!=null);if(t.length)throw new f(`The \`provider\` option cannot be used with ${t.map(e=>`\`${e}\``).join(`, `)}. Configure authentication and the base URL through the provider instead.`)}let{baseURL:n=t?null:W(`OPENAI_BASE_URL`),apiKey:r=t?null:W(`OPENAI_API_KEY`)??null,adminAPIKey:i=t?null:W(`OPENAI_ADMIN_KEY`)??null,organization:a=t?null:W(`OPENAI_ORG_ID`)??null,project:o=t?null:W(`OPENAI_PROJECT_ID`)??null,webhookSecret:c=W(`OPENAI_WEBHOOK_SECRET`)??null,workloadIdentity:l,...u}=e,d=t?ds(t):void 0,p={apiKey:r,adminAPIKey:i,organization:a,project:o,webhookSecret:c,workloadIdentity:l,provider:t,...u,baseURL:d?.baseURL??(n||`https://api.openai.com/v1`)};if(r&&l)throw new f("The `apiKey` and `workloadIdentity` options are mutually exclusive");if(!d&&!r&&!i&&!l)throw new f("Missing credentials. Please pass an `apiKey`, `workloadIdentity`, `adminAPIKey`, or set the `OPENAI_API_KEY` or `OPENAI_ADMIN_KEY` environment variable.");if(!p.dangerouslyAllowBrowser&&_s())throw new f(`It looks like you're running in a browser-like environment.
|
|
9
|
+
|
|
10
|
+
This is disabled by default, as it risks exposing your secret API credentials to attackers.
|
|
11
|
+
If you understand the risks and have appropriate mitigations in place,
|
|
12
|
+
you can set the \`dangerouslyAllowBrowser\` option to \`true\`, e.g.,
|
|
13
|
+
|
|
14
|
+
new OpenAI({ apiKey, dangerouslyAllowBrowser: true });
|
|
15
|
+
|
|
16
|
+
https://help.openai.com/en/articles/5112595-best-practices-for-api-key-safety
|
|
17
|
+
`);this.baseURL=p.baseURL,this.timeout=p.timeout??ps.DEFAULT_TIMEOUT,this.logger=p.logger??console;let m=`warn`;this.logLevel=m,this.logLevel=Pe(p.logLevel,`ClientOptions.logLevel`,this)??Pe(W(`OPENAI_LOG`),`process.env['OPENAI_LOG']`,this)??m,this.fetchOptions=p.fetchOptions,this.maxRetries=p.maxRetries??2,this.fetch=p.fetch??_e(),s(this,ms,it,`f`);let h=t?void 0:W(`OPENAI_CUSTOM_HEADERS`);if(h){let e={};for(let t of h.split(`
|
|
18
|
+
`)){let n=t.indexOf(`:`);n>=0&&(e[t.substring(0,n).trim()]=t.substring(n+1).trim())}p.defaultHeaders=N([e,p.defaultHeaders])}this._options=p,this._provider=d,l&&(this._workloadIdentityAuth=new Mt(l,this.fetch)),this.apiKey=typeof r==`string`?r:null,this.adminAPIKey=i,this.organization=a,this.project=o,this.webhookSecret=c}withOptions(e){let t=this._options.provider,n=e.provider??t,r={...this._options,baseURL:this.baseURL,maxRetries:this.maxRetries,timeout:this.timeout,logger:this.logger,logLevel:this.logLevel,fetch:this.fetch,fetchOptions:this.fetchOptions,apiKey:this._options.apiKey,adminAPIKey:this.adminAPIKey,workloadIdentity:this._options.workloadIdentity,organization:this.organization,project:this.project,webhookSecret:this.webhookSecret};return n&&(delete r.apiKey,delete r.adminAPIKey,delete r.workloadIdentity,delete r.baseURL,n!==t&&(delete r.organization,delete r.project,delete r.defaultHeaders)),new this.constructor({...r,...e,provider:n})}defaultQuery(){return this._options.defaultQuery}validateHeaders({values:e,nulls:t},n={bearerAuth:!0,adminAPIKeyAuth:!0}){if(!(e.get(`authorization`)||e.get(`api-key`))&&!(t.has(`authorization`)||t.has(`api-key`))&&!(this._workloadIdentityAuth&&n.bearerAuth))throw Error(`Could not resolve authentication method. Expected either apiKey or adminAPIKey to be set. Or for one of the "Authorization" or "api-key" headers to be explicitly omitted`)}async authHeaders(e,t={bearerAuth:!0,adminAPIKeyAuth:!0}){return N([t.bearerAuth?await this.bearerAuth(e):null,t.adminAPIKeyAuth?await this.adminAPIKeyAuth(e):null])}async bearerAuth(e){if(this._workloadIdentityAuth)return N([{Authorization:`Bearer ${await this._workloadIdentityAuth.getToken()}`}]);if(this.apiKey!=null)return N([{Authorization:`Bearer ${this.apiKey}`}])}async adminAPIKeyAuth(e){if(this.adminAPIKey!=null)return N([{Authorization:`Bearer ${this.adminAPIKey}`}])}stringifyQuery(e){return Ct(e)}getUserAgent(){return`${this.constructor.name}/JS ${Ye}`}defaultIdempotencyKey(){return`stainless-node-retry-${l()}`}makeStatusError(e,t,n,r){let i=t&&typeof t==`object`&&t.error==null?{error:t}:t;return p.generate(e,i,n,r)}async _callApiKey(){if(this._provider)return!1;let e=this._options.apiKey;if(typeof e!=`function`)return!1;let t;try{t=await e()}catch(e){throw e instanceof f?e:new f(`Failed to get token from 'apiKey' function: ${e.message}`,{cause:e})}if(typeof t!=`string`||!t)throw new f(`Expected 'apiKey' function argument to return a string but it returned ${t}`);return this.apiKey=t,!0}buildURL(e,t,n){let r=!c(this,fs,`m`,gs).call(this)&&n||this.baseURL,i=le(e)?new URL(e):new URL(r+(r.endsWith(`/`)&&e.startsWith(`/`)?e.slice(1):e)),a=this.defaultQuery(),o=Object.fromEntries(i.searchParams);return(!fe(a)||!fe(o))&&(t={...o,...a,...t}),typeof t==`object`&&t&&!Array.isArray(t)&&(i.search=this.stringifyQuery(t)),i.toString()}async prepareOptions(e){this._provider||(e.__security??{bearerAuth:!0}).bearerAuth&&await this._callApiKey()}async prepareRequest(e,{url:t,options:n}){}get(e,t){return this.methodRequest(`get`,e,t)}post(e,t){return this.methodRequest(`post`,e,t)}patch(e,t){return this.methodRequest(`patch`,e,t)}put(e,t){return this.methodRequest(`put`,e,t)}delete(e,t){return this.methodRequest(`delete`,e,t)}methodRequest(e,t,n){return this.request(Promise.resolve(n).then(n=>({method:e,path:t,...n})))}request(e,t=null){return this.responsePromise(this.makeRequest(e,t,void 0))}responsePromise(e,t=(e,t)=>this.parseResponseWithTimeout(e,t)){let n=new Tt(this,e,t);return n.withResponse=async()=>{let t=await n,{response:r}=await e;return{data:t,response:r,request_id:r.headers.get(`x-request-id`)}},n._thenUnwrap=n=>this.responsePromise(e,async(e,r)=>Je(n(await t(e,r),r),r.response)),n}async parseResponseWithTimeout(e,t){if(t.options.stream||t.options.__binaryResponse||t.response.status===204||t.response.headers.get(`content-length`)===`0`)return Ke(e,t);for(;;){let n=c(this,hs,`f`).get(t.controller),r=n?.timeout??t.options.timeout??this.timeout,i=Math.max(0,t.startTime+r-Date.now()),a=t.options.signal,o,s,l=!1;try{if(a?.aborted&&t.options.__metadata?.helperMethod!==`runTools`)throw new m;let n=new Promise((e,n)=>{o=setTimeout(()=>{l=!0,t.controller.abort(),n(new g)},i),a&&(s=()=>n(new m),a.addEventListener(`abort`,s,{once:!0}))});return await Promise.race([Ke(e,t),n])}catch(e){if(a?.aborted)throw new m;if(!l)throw e;let r=n?.retriesRemaining??0;if(!r||t.options.__metadata?.hasStreamingBody||globalThis.ReadableStream&&t.options.body instanceof globalThis.ReadableStream||typeof t.options.body==`object`&&t.options.body!==null&&(Symbol.asyncIterator in t.options.body||Symbol.iterator in t.options.body&&`next`in t.options.body&&typeof t.options.body.next==`function`))throw new g;o!==void 0&&clearTimeout(o),s&&a?.removeEventListener(`abort`,s),s=void 0;let i=await this.retryRequest(t.options,r,t.retryOfRequestLogID??t.requestLogID);Object.assign(t,i)}finally{o!==void 0&&clearTimeout(o),s&&a?.removeEventListener(`abort`,s)}}}async makeRequest(e,t,n){let r=await e,i=r.maxRetries??this.maxRetries;t??=i,await this.prepareOptions(r);let{req:a,url:o,timeout:s}=await this.buildRequest(r,{retryCount:i-t}),l=r.__metadata?.hasStreamingBody===!0;await this.prepareRequest(a,{url:o,options:r}),await this._provider?.prepareRequest?.(a,{url:o,options:r});let f=`log_`+(Math.random()*(1<<24)|0).toString(16).padStart(6,`0`),p=n===void 0?``:`, retryOf: ${n}`,m=Date.now();if(k(this).debug(`[${f}] sending request`,ze({retryOfRequestLogID:n,method:r.method,url:o,options:r,headers:a.headers})),r.signal?.aborted||a.signal?.aborted)throw this._makeUserAbortError(r.signal?.aborted?r.signal:a.signal);let _=r.__security??{bearerAuth:!0},v=this.fetchWithTimeout===ps.prototype.fetchWithTimeout?ys(a.signal):new AbortController,y=await this.fetchWithAuth(o,a,s,v,_).catch(d),b=Date.now();if(y instanceof globalThis.Error){let e=`retrying, ${t} attempts remaining`;if(r.signal?.aborted||a.signal?.aborted)throw this._makeUserAbortError(r.signal?.aborted?r.signal:a.signal);let i=u(y)||/timed? ?out/i.test(String(y)+(`cause`in y?String(y.cause):``));if(t&&!l)return k(this).info(`[${f}] connection ${i?`timed out`:`failed`} - ${e}`),k(this).debug(`[${f}] connection ${i?`timed out`:`failed`} (${e})`,ze({retryOfRequestLogID:n,url:o,durationMs:b-m,message:y.message})),this.retryRequest(r,t,n??f);let s=l?`error; streaming body cannot be retried`:`error; no more retries left`;if(k(this).info(`[${f}] connection ${i?`timed out`:`failed`} - ${s}`),k(this).debug(`[${f}] connection ${i?`timed out`:`failed`} (${s})`,ze({retryOfRequestLogID:n,url:o,durationMs:b-m,message:y.message})),y instanceof oe||y instanceof se)throw y;if(i){let e=`cause`in y?y.cause:void 0,t=typeof e==`object`&&e&&`code`in e&&e.code===`UND_ERR_HEADERS_TIMEOUT`?new g({message:`Request timed out. Node.js fetch timed out waiting for response headers; configure a matching undici fetch and fetchOptions.dispatcher with an Agent whose headersTimeout is at least the SDK timeout.`}):new g;throw Object.assign(t,{cause:y})}throw new h({message:bs(y),cause:y})}let x=`[${f}${p}${[...y.headers.entries()].filter(([e])=>e===`x-request-id`).map(([e,t])=>`, `+e+`: `+JSON.stringify(t)).join(``)}] ${a.method} ${o} ${y.ok?`succeeded`:`failed`} with status ${y.status} in ${b-m}ms`;if(!y.ok){if(y.status===401&&this._workloadIdentityAuth&&_.bearerAuth&&!r.__metadata?.hasStreamingBody&&!r.__metadata?.workloadIdentityTokenRefreshed)return await xe(y.body),this._workloadIdentityAuth.invalidateToken(),this.makeRequest({...r,__metadata:{...r.__metadata,workloadIdentityTokenRefreshed:!0}},t,n??f);let e=await this.shouldRetry(y);if(t&&e&&!l){let e=`retrying, ${t} attempts remaining`;return await xe(y.body),k(this).info(`${x} - ${e}`),k(this).debug(`[${f}] response error (${e})`,ze({retryOfRequestLogID:n,url:y.url,status:y.status,headers:y.headers,durationMs:b-m})),this.retryRequest(r,t,n??f,y.headers)}let i=e?l?`error; streaming body cannot be retried`:`error; no more retries left`:`error; not retryable`;k(this).info(`${x} - ${i}`);let a=await y.text().catch(e=>d(e).message),o=he(a),s=o?void 0:a;throw k(this).debug(`[${f}] response error (${i})`,ze({retryOfRequestLogID:n,url:y.url,status:y.status,headers:y.headers,message:s,durationMs:Date.now()-m})),this.makeStatusError(y.status,o,s,y.headers)}return k(this).info(x),k(this).debug(`[${f}] response start`,ze({retryOfRequestLogID:n,url:y.url,status:y.status,headers:y.headers,durationMs:b-m})),c(this,hs,`f`).set(v,{timeout:s,retriesRemaining:t}),{response:y,options:r,controller:v,requestLogID:f,retryOfRequestLogID:n,startTime:m}}getAPIList(e,t,n){return this.requestAPIList(t,n&&`then`in n?n.then(t=>({method:`get`,path:e,...t})):{method:`get`,path:e,...n})}requestAPIList(e,t){let n=this.makeRequest(t,null,void 0),r=new Ot(this,n,e),i=this.responsePromise(n,async(t,n)=>{let r=await this.parseResponseWithTimeout(t,n);return new e(t,n.response,r,n.options)});return r.then=i.then.bind(i),r.catch=i.catch.bind(i),r.finally=i.finally.bind(i),r.withResponse=i.withResponse.bind(i),r._thenUnwrap=i._thenUnwrap.bind(i),r}async fetchWithAuth(e,t,n,r,i={bearerAuth:!0,adminAPIKeyAuth:!0}){if(this._workloadIdentityAuth&&i.bearerAuth){let e=t.headers,n=e.get(`Authorization`);if(!n||n===`Bearer workload-identity-auth`){let t=await this._workloadIdentityAuth.getToken();e.set(`Authorization`,`Bearer ${t}`)}}return await this.fetchWithTimeout(e,t,n,r)}async fetchWithTimeout(e,t,n,r){let{signal:i,method:a,...o}=t||{},s=this._makeAbort(r),c=!!i&&vs.get(r)===i;i&&!c&&i.addEventListener(`abort`,s,{once:!0});let l=setTimeout(s,n),u=globalThis.ReadableStream&&o.body instanceof globalThis.ReadableStream||typeof o.body==`object`&&o.body!==null&&Symbol.asyncIterator in o.body,d={signal:r.signal,...u?{duplex:`half`}:{},method:`GET`,...o};a&&(d.method=a.toUpperCase());try{return await this.fetch.call(void 0,e,d)}catch(e){throw i&&!c&&i.removeEventListener(`abort`,s),e}finally{clearTimeout(l)}}async shouldRetry(e){let t=e.headers.get(`x-should-retry`);return t===`true`?!0:t===`false`?!1:e.status===408||e.status===409||e.status===429||e.status>=500}async retryRequest(e,t,n,r){let i,a=r?.get(`retry-after-ms`);if(a){let e=parseFloat(a);Number.isNaN(e)||(i=e)}let o=r?.get(`retry-after`);if(o&&i===void 0){let e=parseFloat(o);i=Number.isNaN(e)?Date.parse(o)-Date.now():e*1e3}if(i===void 0||!Number.isFinite(i)||i<0||i>6e4){let n=e.maxRetries??this.maxRetries;i=this.calculateDefaultRetryTimeoutMillis(t,n)}return await ge(i),this.makeRequest(e,t-1,n)}calculateDefaultRetryTimeoutMillis(e,t){let n=t-e;return Math.min(.5*2**n,8)*(1-Math.random()*.25)*1e3}async buildRequest(e,{retryCount:t=0}={}){let n={...e},{method:r,path:i,query:a,defaultBaseURL:o}=n,s=this.buildURL(i,a,o);`timeout`in n&&me(`timeout`,n.timeout),n.timeout=n.timeout??this.timeout;let{bodyHeaders:c,body:l,isStreamingBody:u}=this.buildBody({options:n});return u&&(e.__metadata={...e.__metadata,hasStreamingBody:!0}),{req:{method:r,headers:await this.buildHeaders({options:e,method:r,bodyHeaders:c,retryCount:t}),...n.signal&&{signal:n.signal},...globalThis.ReadableStream&&l instanceof globalThis.ReadableStream&&{duplex:`half`},...l&&{body:l},...this.fetchOptions??{},...n.fetchOptions??{}},url:s,timeout:n.timeout}}async buildHeaders({options:e,method:t,bodyHeaders:n,retryCount:r}){let i={};this.idempotencyHeader&&t!==`get`&&(e.idempotencyKey||=this.defaultIdempotencyKey(),i[this.idempotencyHeader]=e.idempotencyKey);let a=e.__metadata?.helperMethod,o=N([i,{Accept:`application/json`,..._s()?void 0:{"User-Agent":this.getUserAgent()},"X-Stainless-Retry-Count":String(r),...e.timeout?{"X-Stainless-Timeout":String(Math.trunc(e.timeout/1e3))}:{},...rt(),...typeof a==`string`?{"X-Stainless-Helper-Method":a}:{},"OpenAI-Organization":this.organization,"OpenAI-Project":this.project},this._provider?void 0:await this.authHeaders(e,e.__security??{bearerAuth:!0}),this._options.defaultHeaders,n,e.headers]);return this._provider||this.validateHeaders(o,e.__security??{bearerAuth:!0}),o.values}_makeAbort(e){return()=>e.abort()}_makeUserAbortError(e){let t=new m;return Object.defineProperty(t,"cause",{value:e.reason,writable:!0,configurable:!0}),t}buildBody({options:e}){let{body:t,headers:n}=e;if(!t)return t===void 0&&`body`in e?{...c(this,ms,`f`).call(this,{body:t,headers:N([n])}),isStreamingBody:!1}:{bodyHeaders:void 0,body:void 0,isStreamingBody:!1};let r=N([n]),i=globalThis.ReadableStream!==void 0&&t instanceof globalThis.ReadableStream,a=!i&&(typeof t==`string`||t instanceof ArrayBuffer||ArrayBuffer.isView(t)||globalThis.Blob!==void 0&&t instanceof globalThis.Blob||t instanceof URLSearchParams||t instanceof FormData);return ArrayBuffer.isView(t)||t instanceof ArrayBuffer||t instanceof DataView||typeof t==`string`&&r.values.has(`content-type`)||globalThis.Blob&&t instanceof globalThis.Blob||t instanceof FormData||t instanceof URLSearchParams||i?{bodyHeaders:void 0,body:t,isStreamingBody:!a}:typeof t==`object`&&(Symbol.asyncIterator in t||Symbol.iterator in t&&`next`in t&&typeof t.next==`function`)?{bodyHeaders:void 0,body:ye(t),isStreamingBody:!0}:typeof t==`object`&&r.values.get(`content-type`)===`application/x-www-form-urlencoded`?{bodyHeaders:{"content-type":`application/x-www-form-urlencoded`},body:this.stringifyQuery(t),isStreamingBody:!1}:{...c(this,ms,`f`).call(this,{body:t,headers:r}),isStreamingBody:!1}}};ps=$,ms=new WeakMap,hs=new WeakMap,fs=new WeakSet,gs=function(){return this._provider!==void 0||this.baseURL!==`https://api.openai.com/v1`},$.OpenAI=ps,$.DEFAULT_TIMEOUT=6e5,$.OpenAIError=f,$.APIError=p,$.APIConnectionError=h,$.APIConnectionTimeoutError=g,$.APIUserAbortError=m,$.NotFoundError=b,$.ConflictError=x,$.RateLimitError=te,$.BadRequestError=_,$.AuthenticationError=v,$.InternalServerError=ne,$.PermissionDeniedError=y,$.UnprocessableEntityError=ee,$.InvalidWebhookSignatureError=ae,$.toFile=_n,$.toStreamingFile=Lt,$.Completions=Sa,$.Chat=Rr,$.Embeddings=ka,$.Files=Na,$.Images=Wa,$.ContentProvenanceChecks=Ea,$.Audio=vi,$.Moderations=Ka,$.Models=Ga,$.FineTuning=Va,$.Graders=Ua,$.VectorStores=ts,$.Webhooks=os,$.Beta=xa,$.Batches=yi,$.Uploads=Zo,$.Admin=mi,$.Responses=Go,$.Realtime=Ya,$.Conversations=Oa,$.Evals=Ma,$.Containers=Ta,$.Skills=Yo,$.Videos=ns;const vs=new WeakMap;function ys(e){let t=new AbortController;if(!e)return t;let n=globalThis.AbortSignal;if(typeof n?.any!=`function`||!(e instanceof n))return t;try{let r=n.any([t.signal,e]);Object.defineProperty(t,"signal",{value:r,configurable:!0}),vs.set(t,e)}catch{}return t}function bs(e){if(xs(e))return`Connection error. This may be caused by passing an undici dispatcher, such as ProxyAgent, that is incompatible with the fetch implementation. If you are using undici's ProxyAgent, pass the fetch implementation from the same undici package: import { fetch, ProxyAgent } from 'undici'; new OpenAI({ fetch, fetchOptions: { dispatcher: new ProxyAgent(...) } });`}function xs(e){let t=e;for(let e=0;e<8&&t&&typeof t==`object`;e++){let e=t;if(e.code===`UND_ERR_INVALID_ARG`&&typeof e.message==`string`&&e.message.includes(`invalid onRequestStart method`))return!0;t=e.cause}return!1}var Ss=class extends ${constructor({baseURL:e=W(`OPENAI_BASE_URL`),apiKey:t=W(`AZURE_OPENAI_API_KEY`),apiVersion:n=W(`OPENAI_API_VERSION`),endpoint:r,deployment:i,azureADTokenProvider:a,dangerouslyAllowBrowser:o,...s}={}){if(!n)throw new f(`The OPENAI_API_VERSION environment variable is missing or empty; either provide it, or instantiate the AzureOpenAI client with an apiVersion option, like new AzureOpenAI({ apiVersion: 'My API Version' }).`);if(typeof a==`function`&&(o??=!0),!a&&!t)throw new f("Missing credentials. Please pass one of `apiKey` and `azureADTokenProvider`, or set the `AZURE_OPENAI_API_KEY` environment variable.");if(a&&t)throw new f("The `apiKey` and `azureADTokenProvider` arguments are mutually exclusive; only one can be passed at a time.");if(s.defaultQuery={...s.defaultQuery,"api-version":n},!e){if(r||={}.AZURE_OPENAI_ENDPOINT,!r)throw new f("Must provide one of the `baseURL` or `endpoint` arguments, or the `AZURE_OPENAI_ENDPOINT` environment variable");let t=r.length;for(;t>0&&r[t-1]===`/`;)t--;e=`${r.slice(0,t)}/openai`}else if(r)throw new f(`baseURL and endpoint are mutually exclusive`);super({apiKey:a??t,baseURL:e,...s,...o===void 0?{}:{dangerouslyAllowBrowser:o}}),this.apiVersion=``,this.apiVersion=n,this.deploymentName=i}async buildRequest(e,t={}){if(Cs.has(e.path)&&e.method===`post`&&e.body!==void 0){if(!C(e.body))throw Error(`Expected request body to be an object`);let t=this.deploymentName||e.body.model||e.__metadata?.model;t!==void 0&&!this.baseURL.includes(`/deployments`)&&(e.path=I`/deployments/${t}`+e.path)}let n=await super.buildRequest(e,t);return n.req.headers.has(`api-key`)&&(n.req.redirect=`manual`),n}async fetchWithAuth(e,t,n,r,i){return new Headers(t.headers).has(`api-key`)&&(t.redirect=`manual`),super.fetchWithAuth(e,t,n,r,i)}async authHeaders(e,t){let n=t??{bearerAuth:!0,adminAPIKeyAuth:!0};return n.bearerAuth&&typeof this._options.apiKey==`string`?N([{"api-key":this.apiKey}]):super.authHeaders(e,n)}};const Cs=new Set([`/completions`,`/chat/completions`,`/embeddings`,`/audio/transcriptions`,`/audio/translations`,`/audio/speech`,`/images/generations`,`/batches`,`/images/edits`]),ws=`azure-openai`,Ts=`2024-12-01-preview`,Es={id:ws,name:`Azure OpenAI`,description:`GPT models via Azure AI Foundry`,requiresApiKey:!0,apiKeyPlaceholder:`Azure API key`,apiKeyEnvVar:`AZURE_OPENAI_API_KEY`,requiresBaseUrl:!0,baseUrlPlaceholder:`https://your-resource.cognitiveservices.azure.com/`,baseUrlDescription:`Azure resource endpoint`,requiresDeployment:!0,deploymentPlaceholder:`gpt-4.1-mini, gpt-4o, o4-mini`,deploymentDescription:`Comma-separated deployment names (from Azure Portal → Deployments)`,requiresApiVersion:!0,apiVersionDefault:Ts,apiVersionDescription:`Azure OpenAI API version`,getModelIds:()=>{let t=e(ws);if(!t)return[{id:`azure-unconfigured`,name:`Azure OpenAI (set deployments in Settings)`}];let n=t.split(`,`).map(e=>e.trim()).filter(Boolean);return n.length===0?[{id:`azure-unconfigured`,name:`Azure OpenAI (set deployments in Settings)`}]:n.map(e=>{let t=e.startsWith(`o1`)||e.startsWith(`o3`)||e.startsWith(`o4`);return{id:e,name:`${e} (Azure)`,reasoning:t,input:[`text`,`image`]}})}};function Ds(e){return e.replace(/[^a-zA-Z0-9_-]/g,`_`).slice(0,64)}function Os(e,t){let n=o(e.messages,t,Ds),r=[];for(let e of n)if(e.role===`user`){if(typeof e.content==`string`)r.push({role:`user`,content:e.content});else{let t=e.content.map(e=>e.type===`text`?{type:`text`,text:e.text??``}:e.type===`image`?{type:`image_url`,image_url:{url:`data:${e.mimeType};base64,${e.data}`}}:{type:`text`,text:JSON.stringify(e)});r.push({role:`user`,content:t})}}else if(e.role===`assistant`){let t=e.content,n=t.filter(e=>e.type===`text`).map(e=>e.text??``).join(``),i=t.filter(e=>e.type===`toolCall`).map(e=>({id:e.id??``,type:`function`,function:{name:e.name??``,arguments:JSON.stringify(e.arguments??{})}}));i.length?r.push({role:`assistant`,content:n||null,tool_calls:i}):r.push({role:`assistant`,content:n})}else if(e.role===`toolResult`){let t=e.content;r.push({role:`tool`,tool_call_id:e.toolCallId??``,content:t?.map(e=>e.type===`text`?e.text??``:JSON.stringify(e)).join(``)||``})}return r}function ks(e){if(e?.length)return e.map(e=>({type:`function`,function:{name:e.name,description:e.description,parameters:e.parameters}}))}function As(e){let t=e.content.find(e=>e.type===`text`);if(t)return{block:t,index:e.content.indexOf(t)};let n={type:`text`,text:``};return e.content.push(n),{block:n,index:e.content.length-1}}function js(e,t){return e.content.find(e=>e.type===`toolCall`&&e.id===t)}function Ms(e){return{role:`assistant`,content:[],api:`azure-openai-anthropic`,provider:ws,model:e.id,usage:{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},stopReason:`stop`,timestamp:Date.now()}}function Ns(e,n){let r=n.apiKey;if(!r)throw Error(`Azure API key is required`);let i=e.baseUrl;if(!i)throw Error(`Azure endpoint is required`);let a={};e.headers&&Object.assign(a,e.headers),n.headers&&Object.assign(a,n.headers);let o=t(ws)||Ts,s=e.id;return{client:new Ss({endpoint:i.replace(/\/+$/,``),apiKey:r,deployment:s,apiVersion:o,dangerouslyAllowBrowser:!0,defaultHeaders:a}),deployment:s}}function Ps(e,t){return[...e.systemPrompt?[{role:`system`,content:e.systemPrompt}]:[],...Os(e,t)]}function Fs(e,t,n){n&&(e.usage.input=n.prompt_tokens??0,e.usage.output=n.completion_tokens??0,e.usage.totalTokens=n.total_tokens??0,r(t,e.usage))}function Is(e){return e===`tool_calls`?`toolUse`:e===`length`?`length`:`stop`}function Ls(e,t,n){let{block:r,index:i}=As(t);r.text===``&&e.push({type:`text_start`,contentIndex:i,partial:t}),r.text+=n,e.push({type:`text_delta`,contentIndex:i,delta:n,partial:t})}function Rs(e,t,n){let r=n.id?js(t,n.id):void 0;if(r||!n.id)return r;let i={type:`toolCall`,id:n.id,name:n.function?.name??``,arguments:{},_partialJson:``};return t.content.push(i),e.push({type:`toolcall_start`,contentIndex:t.content.length-1,partial:t}),i}function zs(e,t,n,r){n._partialJson+=r;try{n.arguments=JSON.parse(n._partialJson)}catch{}e.push({type:`toolcall_delta`,contentIndex:t.content.indexOf(n),delta:r,partial:t})}function Bs(e,t,n){for(let r of n){let n=Rs(e,t,r);n&&r.function?.arguments&&zs(e,t,n,r.function.arguments)}}function Vs(e,t,n){let r=n.delta;r&&(r.content&&Ls(e,t,r.content),r.tool_calls&&Bs(e,t,r.tool_calls),n.finish_reason&&(t.stopReason=Is(n.finish_reason)))}function Hs(e,t,n,r){try{n.arguments=JSON.parse(n._partialJson||`{}`)}catch{}delete n._partialJson,e.push({type:`toolcall_end`,contentIndex:r,toolCall:n,partial:t})}function Us(e,t){for(let n=0;n<t.content.length;n+=1){let r=t.content[n];r.type===`toolCall`?Hs(e,t,r,n):r.type===`text`&&e.push({type:`text_end`,contentIndex:n,content:r.text,partial:t})}}async function Ws(e,t,n,r,i){let{client:a,deployment:o}=Ns(n,i),s=ks(r.tools),c=await a.chat.completions.create({model:o,messages:Ps(r,n),stream:!0,stream_options:{include_usage:!0},...i.maxTokens?{max_completion_tokens:i.maxTokens}:{},...i.temperature===void 0?{}:{temperature:i.temperature},...s?{tools:s}:{}});e.push({type:`start`,partial:t});for await(let r of c){Fs(t,n,r.usage);for(let n of r.choices??[])Vs(e,t,n)}Us(e,t),e.push({type:`done`,reason:t.stopReason,message:t}),e.end()}function Gs(e,t,n,r){t.stopReason=r?`aborted`:`error`,t.errorMessage=n instanceof Error?n.message:JSON.stringify(n),e.push({type:`error`,reason:t.stopReason,error:t}),e.end()}const Ks=(e,t,r={})=>{let i=n(),a=Ms(e);return Ws(i,a,e,t,r).catch(e=>{Gs(i,a,e,!!r.signal?.aborted)}),i},qs=(e,t,n)=>{let r=n?.apiKey;if(!r)throw Error(`Azure API key is required`);let i=a(e,n,r);return Ks(e,t,{...i})};function Js(){i({api:`azure-openai-anthropic`,stream:Ks,streamSimple:qs})}export{Es as config,Js as register};
|