@cortex-agent/server 2026.10.28 → 2026.12.5
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/LICENSE +255 -21
- package/README.md +36 -7
- package/THIRD_PARTY_NOTICES.txt +1990 -593
- package/defaults/hooks/cortex-hook-api.mjs +2 -1
- package/defaults/hooks/quota-stop.mjs +37 -0
- package/defaults/plugins/cortex-system/skills/client-manage/SKILL.md +23 -15
- package/defaults/prompts/clean-workspace.md +5 -0
- package/dist/agent-adapter/claude/remote-mcp-proxy.js +1 -1
- package/dist/chunks/agent-runner-LVZVKBZX.js +4 -0
- package/dist/chunks/anthropic-messages-TT6454AA.js +8 -0
- package/dist/chunks/azure-openai-responses-52LR2XZD.js +4 -0
- package/dist/chunks/bedrock-converse-stream-EOZGYUNY.js +60 -0
- package/dist/chunks/bowser-MLGGLXTZ.js +20 -0
- package/dist/chunks/child-runner-SMG2VOU5.js +4 -0
- package/dist/chunks/chunk-24DH4IR5.js +4 -0
- package/dist/chunks/chunk-25XKBRDT.js +70 -0
- package/dist/chunks/chunk-2ABET62E.js +23 -0
- package/dist/chunks/chunk-2BVUA256.js +4 -0
- package/dist/chunks/{chunk-LEUENXI2.js → chunk-2WFL62UO.js} +1 -1
- package/dist/chunks/{chunk-OZGBWAT2.js → chunk-2YTYYG4K.js} +1 -1
- package/dist/chunks/chunk-335SSANX.js +4 -0
- package/dist/chunks/chunk-377OPTXX.js +17 -0
- package/dist/chunks/chunk-3EZNVLBF.js +129 -0
- package/dist/chunks/chunk-3O6ZG5HA.js +7 -0
- package/dist/chunks/{chunk-6AKUD3CF.js → chunk-3XLHL5YT.js} +1 -1
- package/dist/chunks/chunk-4HRI75GU.js +4 -0
- package/dist/chunks/chunk-4JBYLRPM.js +57 -0
- package/dist/chunks/chunk-4KKV7VKE.js +4 -0
- package/dist/chunks/chunk-4KQHDDC5.js +4 -0
- package/dist/chunks/chunk-4SWD4JMP.js +33 -0
- package/dist/chunks/chunk-52VCLZS5.js +4 -0
- package/dist/chunks/chunk-54P7TSY3.js +10 -0
- package/dist/chunks/chunk-5DVSAXOI.js +7 -0
- package/dist/chunks/chunk-5F3A62YS.js +4 -0
- package/dist/chunks/{chunk-XNSSUVT6.js → chunk-5FHETFZM.js} +1 -1
- package/dist/chunks/{chunk-A34TDMIC.js → chunk-5LBLRAHS.js} +1 -1
- package/dist/chunks/chunk-5UYVNA3W.js +4 -0
- package/dist/chunks/chunk-6G3OYMCV.js +21 -0
- package/dist/chunks/chunk-7GGPYU5E.js +30 -0
- package/dist/chunks/chunk-7TYSMLUV.js +4 -0
- package/dist/chunks/chunk-7W7VYUTK.js +5 -0
- package/dist/chunks/chunk-AXYAZTTN.js +6 -0
- package/dist/chunks/{chunk-BGVHA2D4.js → chunk-B3NB243Z.js} +1 -1
- package/dist/chunks/chunk-BKYP6AGM.js +8 -0
- package/dist/chunks/chunk-BVEDNESB.js +4 -0
- package/dist/chunks/chunk-BWDJS6A4.js +12 -0
- package/dist/chunks/chunk-C6YVF7EI.js +4 -0
- package/dist/chunks/chunk-CEJIYYVE.js +15 -0
- package/dist/chunks/chunk-CI2RHH74.js +50 -0
- package/dist/chunks/chunk-CMSOOLJB.js +4 -0
- package/dist/chunks/chunk-CSVTYYLP.js +4 -0
- package/dist/chunks/chunk-DE5EGVKG.js +6 -0
- package/dist/chunks/{chunk-E6BYRULL.js → chunk-DK3RPZOQ.js} +1 -1
- package/dist/chunks/{chunk-YPK2CAIZ.js → chunk-DK4UCK7L.js} +1 -1
- package/dist/chunks/chunk-DYLBVUAU.js +4 -0
- package/dist/chunks/chunk-FDC2GRBK.js +27 -0
- package/dist/chunks/chunk-FE7HH5JS.js +18 -0
- package/dist/chunks/chunk-FYD57YRO.js +436 -0
- package/dist/chunks/chunk-G264APQN.js +5 -0
- package/dist/chunks/chunk-G4JYZFEO.js +11 -0
- package/dist/chunks/chunk-GFFM56U2.js +4 -0
- package/dist/chunks/chunk-GOS3P7KS.js +132 -0
- package/dist/chunks/chunk-HVN37UXD.js +4 -0
- package/dist/chunks/chunk-IA6IODY3.js +4 -0
- package/dist/chunks/{chunk-HU6UIDEJ.js → chunk-IGZWZP7Z.js} +1 -1
- package/dist/chunks/{chunk-NR6U3WIZ.js → chunk-IJ7XFQMI.js} +1 -1
- package/dist/chunks/chunk-IMMGYDAB.js +6 -0
- package/dist/chunks/chunk-IOWBF7UK.js +10 -0
- package/dist/chunks/{chunk-HALUQ7ZF.js → chunk-ITGCWQFK.js} +1 -1
- package/dist/chunks/chunk-IVZ7QUEG.js +4 -0
- package/dist/chunks/{chunk-YAEVYJAR.js → chunk-IWY2HIFK.js} +1 -1
- package/dist/chunks/{chunk-KGJZAYQD.js → chunk-J7OBATRN.js} +1 -1
- package/dist/chunks/{chunk-QWAQHHRS.js → chunk-JGUEIW2W.js} +1 -1
- package/dist/chunks/chunk-JKL3AK5D.js +106 -0
- package/dist/chunks/chunk-JZ7U7RUK.js +351 -0
- package/dist/chunks/chunk-KJUQCCB5.js +4 -0
- package/dist/chunks/chunk-KST6OY76.js +10 -0
- package/dist/chunks/chunk-KZSAFVSY.js +129 -0
- package/dist/chunks/chunk-LD2ZSH3M.js +903 -0
- package/dist/chunks/chunk-LE6QPXN6.js +7 -0
- package/dist/chunks/chunk-LEAV3FFG.js +4 -0
- package/dist/chunks/chunk-LIIZI3HY.js +5 -0
- package/dist/chunks/chunk-LP72AF56.js +45 -0
- package/dist/chunks/{chunk-FXDIR3SQ.js → chunk-MJQ2D2OP.js} +1 -1
- package/dist/chunks/{chunk-6LZK4DDH.js → chunk-NHHR4DCF.js} +1 -1
- package/dist/chunks/chunk-NW4GW47L.js +4 -0
- package/dist/chunks/chunk-OALEJ6FG.js +60 -0
- package/dist/chunks/chunk-OIV4DIMB.js +4 -0
- package/dist/chunks/chunk-OJ37ZWBG.js +4 -0
- package/dist/chunks/chunk-OZXMPBUX.js +4 -0
- package/dist/chunks/{chunk-3THJYAEF.js → chunk-PG7452XE.js} +1 -1
- package/dist/chunks/chunk-PJCUB7YJ.js +4 -0
- package/dist/chunks/chunk-PTS3J4DQ.js +6 -0
- package/dist/chunks/{chunk-PXS5SHOV.js → chunk-PVVEEBUU.js} +1 -1
- package/dist/chunks/chunk-Q7BZLPBU.js +8 -0
- package/dist/chunks/{chunk-FOJQXLL2.js → chunk-QC66ZXPP.js} +1 -1
- package/dist/chunks/chunk-QXFWIL4C.js +4 -0
- package/dist/chunks/{chunk-PFMEUFJ7.js → chunk-R2CCD4OF.js} +1 -1
- package/dist/chunks/chunk-R6CGBSTC.js +22 -0
- package/dist/chunks/chunk-RG5GP4RB.js +5 -0
- package/dist/chunks/{chunk-D3NXKK2L.js → chunk-RW2F2QNP.js} +1 -1
- package/dist/chunks/{models-L5VF4I5O-XXNJYQMQ.js → chunk-RWPO3NZ3.js} +1 -1
- package/dist/chunks/chunk-SAJD4EKE.js +10 -0
- package/dist/chunks/chunk-SDUS2H3E.js +4 -0
- package/dist/chunks/chunk-SIHGKM4E.js +4 -0
- package/dist/chunks/chunk-SKHFU5DI.js +4 -0
- package/dist/chunks/{chunk-STUHNKQS.js → chunk-SM45TH22.js} +1 -1
- package/dist/chunks/chunk-T54CZKNJ.js +6 -0
- package/dist/chunks/chunk-TKFFQNAP.js +19 -0
- package/dist/chunks/chunk-TMV2ZDOI.js +18 -0
- package/dist/chunks/chunk-TRXLIL7V.js +4 -0
- package/dist/chunks/{chunk-SUFW24P4.js → chunk-UEEW2R4E.js} +1 -1
- package/dist/chunks/chunk-UHXPRU6G.js +10 -0
- package/dist/chunks/chunk-UPQVWHZ3.js +4 -0
- package/dist/chunks/{chunk-JERCOLY3.js → chunk-V35MFAUQ.js} +4 -6
- package/dist/chunks/chunk-V7K3KNDM.js +4 -0
- package/dist/chunks/chunk-VHX2GHBF.js +4 -0
- package/dist/chunks/chunk-VOAKRJ4R.js +4 -0
- package/dist/chunks/{chunk-X2GYYRVM.js → chunk-VW7TLY3P.js} +1 -1
- package/dist/chunks/chunk-W34AK4SK.js +65 -0
- package/dist/chunks/{chunk-REBNWCKI.js → chunk-WU7RNAZD.js} +1 -1
- package/dist/chunks/chunk-WZC4TDDM.js +6 -0
- package/dist/chunks/chunk-WZYS2HAK.js +4 -0
- package/dist/chunks/chunk-X2TKJ7KR.js +11 -0
- package/dist/chunks/{chunk-H2FP6DG4.js → chunk-X5ND4H4P.js} +1 -1
- package/dist/chunks/{chunk-4U7XXM4W.js → chunk-Y3AOGNDT.js} +1 -1
- package/dist/chunks/chunk-Y6DGVTKM.js +6 -0
- package/dist/chunks/{chunk-KENCMLRE.js → chunk-YAEHSSR4.js} +1 -1
- package/dist/chunks/chunk-YWPBE5LP.js +4 -0
- package/dist/chunks/chunk-ZAVX7G2M.js +15 -0
- package/dist/chunks/chunk-ZD2M73XA.js +19 -0
- package/dist/chunks/chunk-ZD4O6NPV.js +4 -0
- package/dist/chunks/chunk-ZNAMETPQ.js +4 -0
- package/dist/chunks/chunk-ZY6N5LVQ.js +4 -0
- package/dist/chunks/chunk-ZYQ4TDTT.js +81 -0
- package/dist/chunks/cli-VB2N7HEK.js +55 -0
- package/dist/chunks/cloudflare-workers-ai-system-one-YKU742EC.js +4 -0
- package/dist/chunks/context-CI2FKEQE.js +4 -0
- package/dist/chunks/cost-CZRRSIUF.js +5 -0
- package/dist/chunks/dist-QCNQN6DY.js +4 -0
- package/dist/chunks/easter-egg-3d-XR5S2O3T.js +4 -0
- package/dist/chunks/{event-streams-3JSFPOTZ.js → event-streams-AVE4MSS6.js} +1 -1
- package/dist/chunks/{execution-repo-ZLJTBWFC.js → execution-repo-5TLV2NM4.js} +1 -1
- package/dist/chunks/{executions-6ARGR3IO.js → executions-I3UUIGSL.js} +1 -1
- package/dist/chunks/file-Y5G56IUT.js +4 -0
- package/dist/chunks/github-copilot-BRU2SRRZ.js +4 -0
- package/dist/chunks/google-generative-ai-ZF5QEUZV.js +4 -0
- package/dist/chunks/google-vertex-4PJZZI3Y.js +4 -0
- package/dist/chunks/init-A6GY656J.js +4 -0
- package/dist/chunks/{install-cli-4IZCSDFZ.js → install-cli-FALWKQYO.js} +1 -1
- package/dist/chunks/{interaction-ask-G5T3H3CG.js → interaction-ask-O5HGF6CH.js} +1 -1
- package/dist/chunks/{interaction-plan-E5V42MUP.js → interaction-plan-JTVDN3BC.js} +1 -1
- package/dist/chunks/kimi-coding-ZCIBMDZ6.js +4 -0
- package/dist/chunks/{llama-cpp-classify-OTXZWCMW.js → llama-cpp-classify-NRUXAIGQ.js} +3 -3
- package/dist/chunks/local-client-stop-RS4AHNF4.js +4 -0
- package/dist/chunks/{memory-cli-PYOILNN5.js → memory-cli-DIT4DQF3.js} +1 -1
- package/dist/chunks/meta-JQH66YU7.js +4 -0
- package/dist/chunks/mistral-conversations-CXHOECUV.js +7 -0
- package/dist/chunks/model-resolver-GIBPYRKP.js +4 -0
- package/dist/chunks/monitor-Z2HKNY5E.js +4 -0
- package/dist/chunks/{node-PTK2HCDV.js → node-DAO3SX7O.js} +1 -1
- package/dist/chunks/{openai-codex-2REL6UQU.js → openai-codex-JULCKICT.js} +1 -1
- package/dist/chunks/openai-codex-responses-U6DGMGDK.js +12 -0
- package/dist/chunks/openai-completions-PP4XLLOM.js +9 -0
- package/dist/chunks/{openai-decisions-2N6ZRPZC.js → openai-decisions-JU6QQKEM.js} +1 -1
- package/dist/chunks/openai-responses-2SG757TL.js +6 -0
- package/dist/chunks/openrouter-images-32M7YZWC.js +4 -0
- package/dist/chunks/pi-messages-VSINMXN4.js +10 -0
- package/dist/chunks/radius-THYKWV4E.js +4 -0
- package/dist/chunks/remote-ops-2WBEFQ3E.js +14 -0
- package/dist/chunks/runner-5MKMRTIN.js +4 -0
- package/dist/chunks/runtime-DST3H5JP.js +4 -0
- package/dist/chunks/schedule-cli-V7Y2BBVY.js +4 -0
- package/dist/chunks/slack-R7SEJYMY.js +4 -0
- package/dist/chunks/start-ui-http-7K5JOLPU.js +43 -0
- package/dist/chunks/subagent-Z5IQ4L54.js +4 -0
- package/dist/chunks/{time-KEHDQT6K.js → time-P6PE52WL.js} +1 -1
- package/dist/chunks/tool-shims-YCXZWTST.js +4 -0
- package/dist/chunks/typesafe-system-one-M2DABJSZ.js +4 -0
- package/dist/chunks/ui-board-HQIE4RZG.js +5 -0
- package/dist/chunks/ui-decision-YBZDS4YW.js +4 -0
- package/dist/chunks/{ui-file-GVH53O3X.js → ui-file-SRD4ILBS.js} +1 -1
- package/dist/chunks/ui-view-Z25MTZT7.js +4 -0
- package/dist/chunks/virtual-modules-H4DXPJZB.js +4 -0
- package/dist/chunks/waitpoint-M6JZBSLT.js +5 -0
- package/dist/chunks/workers-SQ2R32TK.js +4 -0
- package/dist/client-bundle/client.mjs +273 -93
- package/dist/client-bundle/manifest.json +2 -2
- package/dist/core/pi-sdk.js +1 -1
- package/dist/domain/auth/cc-auth-cli.js +1 -1
- package/dist/domain/mcp/bundled-server.js +1 -1
- package/dist/domain/mcp/feishu/client.js +4 -0
- package/dist/entry/app.js +151 -559
- package/dist/entry/browser-cli.js +10 -10
- package/dist/entry/cli.js +1 -1
- package/dist/entry/cortex-cli.js +1 -1
- package/dist/entry/daemon.js +4 -4
- package/dist/entry/hook-cli.js +2 -2
- package/dist/entry/production-app-bootstrap.js +1 -1
- package/dist/entry/production-evidence-export-cli.js +1 -1
- package/dist/entry/signal-cli.js +2 -2
- package/dist/tui/index.js +41 -41
- package/package.json +3 -3
- package/vendor/pi/CHANGELOG.md +330 -0
- package/vendor/pi/dist/codemode-worker.js +2 -0
- package/vendor/pi/dist/core/export-html/ansi-to-html.js +57 -20
- package/vendor/pi/dist/core/export-html/template.css +9 -0
- package/vendor/pi/dist/core/export-html/template.js +166 -46
- package/vendor/pi/dist/core/export-html/tool-renderer.js +5 -3
- package/vendor/pi/dist/core/extensions/loader.js +1 -1
- package/vendor/pi/dist/extensions/codemode/execute.js +15 -13
- package/vendor/pi/dist/modes/interactive/theme/theme.js +36 -23
- package/vendor/pi/dist/utils/image-resize-worker.js +1 -1
- package/vendor/pi/dist/utils/image-resize.js +1 -1
- package/vendor/pi/docs/cli.md +35 -12
- package/vendor/pi/docs/custom-provider.md +2 -0
- package/vendor/pi/docs/environment-variables.md +2 -0
- package/vendor/pi/docs/extensions.md +3192 -225
- package/vendor/pi/docs/keybindings.md +2 -2
- package/vendor/pi/docs/llama-cpp.md +27 -19
- package/vendor/pi/docs/mcp.md +6 -4
- package/vendor/pi/docs/message-types.md +1 -1
- package/vendor/pi/docs/models-configuration.md +9 -3
- package/vendor/pi/docs/models.md +2 -1
- package/vendor/pi/docs/nvidia-rtx-llama-cpp.md +5 -5
- package/vendor/pi/docs/packages.md +24 -0
- package/vendor/pi/docs/prompt-templates.md +1 -1
- package/vendor/pi/docs/providers.md +4 -2
- package/vendor/pi/docs/quickstart.md +7 -3
- package/vendor/pi/docs/rpc-commands.md +1 -1
- package/vendor/pi/docs/rpc.md +4 -2
- package/vendor/pi/docs/sessions.md +17 -3
- package/vendor/pi/docs/settings.md +6 -5
- package/vendor/pi/docs/slash-commands.md +3 -2
- package/vendor/pi/docs/terminal-setup.md +3 -1
- package/vendor/pi/docs/tmux.md +6 -0
- package/vendor/pi/docs/tui.md +4 -0
- package/vendor/pi/docs/windows.md +27 -0
- package/vendor/pi/examples/extensions/README.md +2 -1
- package/vendor/pi/examples/extensions/custom-provider-anthropic/index.ts +27 -31
- package/vendor/pi/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/vendor/pi/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/vendor/pi/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/vendor/pi/examples/extensions/debug-provider.ts +2 -2
- package/vendor/pi/examples/extensions/gondolin/index.ts +4 -7
- package/vendor/pi/examples/extensions/gondolin/package-lock.json +19 -29
- package/vendor/pi/examples/extensions/gondolin/package.json +2 -2
- package/vendor/pi/examples/extensions/plan-mode/index.ts +23 -13
- package/vendor/pi/examples/extensions/plan-mode/utils.ts +42 -16
- package/vendor/pi/examples/extensions/preset.ts +2 -0
- package/vendor/pi/examples/extensions/reload-runtime.ts +17 -5
- package/vendor/pi/examples/extensions/subagent/README.md +14 -11
- package/vendor/pi/examples/extensions/subagent/index.ts +392 -171
- package/vendor/pi/examples/extensions/todo.ts +7 -0
- package/vendor/pi/examples/extensions/tools.ts +2 -0
- package/vendor/pi/examples/extensions/with-deps/package-lock.json +2 -2
- package/vendor/pi/examples/extensions/with-deps/package.json +1 -1
- package/vendor/pi/examples/tsconfig.json +208 -0
- package/vendor/pi/package.json +15 -16
- package/vendor/pi/schemas/models.schema.json +66 -37
- package/vendor/pi/schemas/settings.schema.json +18 -1
- package/vendor/pi-ai/bedrock.js +1 -1
- package/vendor/pi-ai/oauth-load.js +1 -1
- package/web/dist/assets/{board-math-css-BPXakv_3.js → board-math-css-DKX6FcUS.js} +1 -1
- package/web/dist/assets/index-D11wi0uG.js +540 -0
- package/web/dist/assets/index-JedYumhY.css +1 -0
- package/web/dist/assets/{index-WCm6wwmM.js → index-jl30Gy8P.js} +1 -1
- package/web/dist/assets/pdf-worker-DdZgk2mV.js +57 -0
- package/web/dist/assets/pdf.worker.min-Bz_KHX45.js +55 -0
- package/web/dist/index.html +2 -2
- package/web/dist/theme.css +22 -0
- package/dist/chunks/anthropic-messages-M3SMXACA.js +0 -8
- package/dist/chunks/api-GM53PHIL-GFHEXXE6.js +0 -4
- package/dist/chunks/azure-openai-responses-76YWXHSB.js +0 -4
- package/dist/chunks/bedrock-converse-stream-5UPX4NTQ.js +0 -58
- package/dist/chunks/child-runner-3GHOWGZP.js +0 -4
- package/dist/chunks/chunk-2ZNLUY2U.js +0 -128
- package/dist/chunks/chunk-3F6WW7HR.js +0 -13
- package/dist/chunks/chunk-3OKHUVEM.js +0 -7
- package/dist/chunks/chunk-3YHOCPQU.js +0 -10
- package/dist/chunks/chunk-4EX2JJWB.js +0 -4
- package/dist/chunks/chunk-4LLH5OWM.js +0 -10
- package/dist/chunks/chunk-52T37Y47.js +0 -8
- package/dist/chunks/chunk-7MU2AKNM.js +0 -4
- package/dist/chunks/chunk-AAA3UBIS.js +0 -4
- package/dist/chunks/chunk-ASYQHJVQ.js +0 -9
- package/dist/chunks/chunk-BKHDWCRT.js +0 -79
- package/dist/chunks/chunk-CQLH4UVX.js +0 -4
- package/dist/chunks/chunk-CVC66CFV.js +0 -33
- package/dist/chunks/chunk-D6UA4BZC.js +0 -19
- package/dist/chunks/chunk-DGMNI4AO.js +0 -4
- package/dist/chunks/chunk-DHSA5ACV.js +0 -125
- package/dist/chunks/chunk-DPQPXBTP.js +0 -68
- package/dist/chunks/chunk-DXBSQXJL.js +0 -18
- package/dist/chunks/chunk-E7ZMYIY6.js +0 -30
- package/dist/chunks/chunk-EQITBTJC.js +0 -10
- package/dist/chunks/chunk-EXJA5RIX.js +0 -357
- package/dist/chunks/chunk-FF7UELTU.js +0 -4
- package/dist/chunks/chunk-FH74NME3.js +0 -115
- package/dist/chunks/chunk-FOQ7VLIL.js +0 -17
- package/dist/chunks/chunk-FX6MOGLR.js +0 -11
- package/dist/chunks/chunk-G2V65UBA.js +0 -4
- package/dist/chunks/chunk-HGPBHTVD.js +0 -6
- package/dist/chunks/chunk-J5DVLUKY.js +0 -6
- package/dist/chunks/chunk-JW2HFMTF.js +0 -4
- package/dist/chunks/chunk-KDYEGGMW.js +0 -4
- package/dist/chunks/chunk-KIGMAATV.js +0 -23
- package/dist/chunks/chunk-KIU5FAPY.js +0 -5
- package/dist/chunks/chunk-KIWMQPH7.js +0 -739
- package/dist/chunks/chunk-L6VCIGWS.js +0 -11
- package/dist/chunks/chunk-LACGULCN.js +0 -10
- package/dist/chunks/chunk-LMSQZ6TQ.js +0 -4
- package/dist/chunks/chunk-MEPASGPP.js +0 -6
- package/dist/chunks/chunk-MFAEUHMV.js +0 -28
- package/dist/chunks/chunk-NAA7GF6Q.js +0 -5
- package/dist/chunks/chunk-NKDMKRSB.js +0 -68
- package/dist/chunks/chunk-NKXV32S6.js +0 -4
- package/dist/chunks/chunk-NVX5IPRN.js +0 -4
- package/dist/chunks/chunk-O3JW2F7D.js +0 -8
- package/dist/chunks/chunk-OE4KH3NJ.js +0 -4
- package/dist/chunks/chunk-OISO5JXB.js +0 -4
- package/dist/chunks/chunk-OPYXNSMY.js +0 -4
- package/dist/chunks/chunk-OSEIQ7SS.js +0 -4
- package/dist/chunks/chunk-P52RMIYX.js +0 -6
- package/dist/chunks/chunk-PBJ5MPPX.js +0 -60
- package/dist/chunks/chunk-PZMGBKUR.js +0 -13
- package/dist/chunks/chunk-PZMXHA6X.js +0 -9
- package/dist/chunks/chunk-Q7CE3UIE.js +0 -133
- package/dist/chunks/chunk-QBKCAIJG.js +0 -4
- package/dist/chunks/chunk-QEOFEETJ.js +0 -4
- package/dist/chunks/chunk-QUUEQRIT.js +0 -4
- package/dist/chunks/chunk-RA6HKFBV.js +0 -4
- package/dist/chunks/chunk-REPYBMQS.js +0 -4
- package/dist/chunks/chunk-SKHLZ6XY.js +0 -9
- package/dist/chunks/chunk-TAWLERZA.js +0 -4
- package/dist/chunks/chunk-TWAEABGG.js +0 -52
- package/dist/chunks/chunk-TZFLHVOQ.js +0 -7
- package/dist/chunks/chunk-UD3NMUHR.js +0 -12
- package/dist/chunks/chunk-UNVEZI57.js +0 -4
- package/dist/chunks/chunk-VQUPKMDR.js +0 -4
- package/dist/chunks/chunk-W25TB3PU.js +0 -4
- package/dist/chunks/chunk-W5LGYSPZ.js +0 -4
- package/dist/chunks/chunk-WEZWKMYU.js +0 -4
- package/dist/chunks/chunk-XAJLZR7C.js +0 -28
- package/dist/chunks/chunk-XH6FMP3N.js +0 -71
- package/dist/chunks/chunk-XSRZHN63.js +0 -4
- package/dist/chunks/chunk-Y3GFB5XM.js +0 -8
- package/dist/chunks/chunk-YG7OEPR2.js +0 -6
- package/dist/chunks/chunk-YHIWOGVL.js +0 -4
- package/dist/chunks/chunk-YKKEI5GI.js +0 -4
- package/dist/chunks/chunk-YZSHTWNM.js +0 -92
- package/dist/chunks/chunk-Z4H3VDHI.js +0 -4
- package/dist/chunks/cli-5DBTRMHU.js +0 -53
- package/dist/chunks/client-XOGYH5UR.js +0 -4
- package/dist/chunks/cloudflare-workers-ai-system-one-32JCFHI3.js +0 -4
- package/dist/chunks/config-DJSQI77S-335IXHSM.js +0 -4
- package/dist/chunks/context-VCQH5OB6.js +0 -4
- package/dist/chunks/cost-PGGFI7QJ.js +0 -5
- package/dist/chunks/dist-PUKMZ7GW.js +0 -4
- package/dist/chunks/easter-egg-3d-MO4MOEVF.js +0 -4
- package/dist/chunks/es5-VNTQPCKX.js +0 -4
- package/dist/chunks/file-7BN7RCAY.js +0 -4
- package/dist/chunks/gateway-UCRPMR75.js +0 -36
- package/dist/chunks/github-copilot-HAI2DA62.js +0 -4
- package/dist/chunks/google-generative-ai-2VXWLHWI.js +0 -4
- package/dist/chunks/google-vertex-UA36QP2U.js +0 -4
- package/dist/chunks/init-HA7FAQ73.js +0 -4
- package/dist/chunks/kimi-coding-HMJRKCPA.js +0 -4
- package/dist/chunks/local-client-stop-SQRU7ZZM.js +0 -4
- package/dist/chunks/meta-KY3LNFV2.js +0 -4
- package/dist/chunks/mistral-conversations-34F66L3O.js +0 -7
- package/dist/chunks/model-resolver-N3DTAQ2S.js +0 -4
- package/dist/chunks/openai-codex-responses-ZBVHREB3.js +0 -12
- package/dist/chunks/openai-completions-VVIB26SH.js +0 -9
- package/dist/chunks/openai-responses-735XA2ZX.js +0 -6
- package/dist/chunks/openrouter-images-3IKETHAC.js +0 -4
- package/dist/chunks/pi-messages-I3E4ZFHA.js +0 -10
- package/dist/chunks/radius-HXRZVBDB.js +0 -4
- package/dist/chunks/remote-ops-BALZYKH6.js +0 -14
- package/dist/chunks/runner-PLVZDGHB.js +0 -4
- package/dist/chunks/runtime-6YLTA2ZD.js +0 -4
- package/dist/chunks/schedule-cli-OLASBBYJ.js +0 -4
- package/dist/chunks/slack-WAGSPZUX.js +0 -4
- package/dist/chunks/start-ui-http-QALT7C3P.js +0 -43
- package/dist/chunks/subagent-E3UC7ZHC.js +0 -4
- package/dist/chunks/tool-shims-Q6P6UXVC.js +0 -4
- package/dist/chunks/typesafe-system-one-6ULACYD4.js +0 -4
- package/dist/chunks/ui-board-4GYW6KKW.js +0 -5
- package/dist/chunks/ui-decision-U2FXSEC2.js +0 -4
- package/dist/chunks/ui-view-O7PLANT7.js +0 -4
- package/dist/chunks/virtual-modules-IDC5YKZJ.js +0 -4
- package/dist/chunks/waitpoint-2FGQBIAC.js +0 -5
- package/dist/chunks/workers-XN4PSTH6.js +0 -4
- package/vendor/aistatus/gateway-cli.js +0 -21
- package/vendor/pi/examples/extensions/sandbox/index.ts +0 -321
- package/vendor/pi/examples/extensions/sandbox/package-lock.json +0 -92
- package/vendor/pi/examples/extensions/sandbox/package.json +0 -19
- package/web/dist/assets/index-BHZpFXhc.js +0 -525
- package/web/dist/assets/index-DqWMdMkh.css +0 -1
- package/web/dist/assets/pdf-worker-Hp15W1QJ.js +0 -57
- package/web/dist/assets/pdf.worker.min-DnhTvCwe.js +0 -55
|
@@ -9,7 +9,7 @@ import{c as zr,e as Ia}from"./chunk-WHC7AYZD.js";var Bo=zr(ee=>{"use strict";var
|
|
|
9
9
|
${i.map(m=>m.error).join(`
|
|
10
10
|
`)}
|
|
11
11
|
${o}
|
|
12
|
-
${p}`)}return o},d=uc(No);var Ze=class extends w{retrieve(s,e={},t){let{betas:r,workspace_id:i}=e??{};return this._client.get(d`/v1/deployment_runs/${s}?beta=true`,{...t,headers:l([{"anthropic-beta":[...r??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}list(s={},e){let{betas:t,workspace_id:r,...i}=s??{};return this._client.getAPIList("/v1/deployment_runs?beta=true",S,{query:i,...e,headers:l([{"anthropic-beta":[...t??[],"managed-agents-2026-04-01"].toString(),...r!=null?{"anthropic-workspace-id":r}:void 0},e?.headers])})}};var et=class extends w{create(s,e){let{betas:t,workspace_id:r,...i}=s;return this._client.post("/v1/deployments?beta=true",{body:i,...e,headers:l([{"anthropic-beta":[...t??[],"managed-agents-2026-04-01"].toString(),...r!=null?{"anthropic-workspace-id":r}:void 0},e?.headers])})}retrieve(s,e={},t){let{betas:r,workspace_id:i}=e??{};return this._client.get(d`/v1/deployments/${s}?beta=true`,{...t,headers:l([{"anthropic-beta":[...r??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}update(s,e,t){let{betas:r,workspace_id:i,...o}=e;return this._client.post(d`/v1/deployments/${s}?beta=true`,{body:o,...t,headers:l([{"anthropic-beta":[...r??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}list(s={},e){let{betas:t,workspace_id:r,...i}=s??{};return this._client.getAPIList("/v1/deployments?beta=true",S,{query:i,...e,headers:l([{"anthropic-beta":[...t??[],"managed-agents-2026-04-01"].toString(),...r!=null?{"anthropic-workspace-id":r}:void 0},e?.headers])})}archive(s,e={},t){let{betas:r,workspace_id:i}=e??{};return this._client.post(d`/v1/deployments/${s}/archive?beta=true`,{...t,headers:l([{"anthropic-beta":[...r??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}pause(s,e={},t){let{betas:r,workspace_id:i}=e??{};return this._client.post(d`/v1/deployments/${s}/pause?beta=true`,{...t,headers:l([{"anthropic-beta":[...r??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}run(s,e={},t){let{betas:r,workspace_id:i}=e??{};return this._client.post(d`/v1/deployments/${s}/run?beta=true`,{...t,headers:l([{"anthropic-beta":[...r??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}unpause(s,e={},t){let{betas:r,workspace_id:i}=e??{};return this._client.post(d`/v1/deployments/${s}/unpause?beta=true`,{...t,headers:l([{"anthropic-beta":[...r??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}};var tt=class extends w{create(s,e){let{betas:t,workspace_id:r,...i}=s;return this._client.post("/v1/dreams?beta=true",{body:i,...e,headers:l([{"anthropic-beta":[...t??[],"dreaming-2026-04-21"].toString(),...r!=null?{"anthropic-workspace-id":r}:void 0},e?.headers])})}retrieve(s,e={},t){let{betas:r,workspace_id:i}=e??{};return this._client.get(d`/v1/dreams/${s}?beta=true`,{...t,headers:l([{"anthropic-beta":[...r??[],"dreaming-2026-04-21"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}list(s={},e){let{betas:t,workspace_id:r,...i}=s??{};return this._client.getAPIList("/v1/dreams?beta=true",S,{query:i,...e,headers:l([{"anthropic-beta":[...t??[],"dreaming-2026-04-21"].toString(),...r!=null?{"anthropic-workspace-id":r}:void 0},e?.headers])})}archive(s,e={},t){let{betas:r,workspace_id:i}=e??{};return this._client.post(d`/v1/dreams/${s}/archive?beta=true`,{...t,headers:l([{"anthropic-beta":[...r??[],"dreaming-2026-04-21"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}cancel(s,e={},t){let{betas:r,workspace_id:i}=e??{};return this._client.post(d`/v1/dreams/${s}/cancel?beta=true`,{...t,headers:l([{"anthropic-beta":[...r??[],"dreaming-2026-04-21"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}};var Be="x-stainless-helper",nt="x-stainless-helper-method";function _n(n){return{[Be]:n}}var rt=Symbol("anthropic.sdk.stainlessHelper");function mr(n){return typeof n=="object"&&n!==null&&rt in n}function Qs(n,s){let e=new Set;if(n)for(let t of n)mr(t)&&e.add(t[rt]);if(s)for(let t of s){mr(t)&&e.add(t[rt]);let r=t.content;if(Array.isArray(r))for(let i of r){mr(i)&&e.add(i[rt]);let o=i?.tool?.definition;mr(o)&&e.add(o[rt])}}return Array.from(e)}function gn(n,s){let e=Qs(n,s);return e.length===0?{}:{[Be]:e.join(", ")}}function wn(n){return mr(n)?{[Be]:n[rt]}:{}}var st=class extends w{list(s={},e){let{betas:t,workspace_id:r,...i}=s??{};return this._client.getAPIList("/v1/files?beta=true",S,{query:i,...e,headers:l([{...t?.toString()!=null?{"anthropic-beta":t?.toString()}:void 0,...r!=null?{"anthropic-workspace-id":r}:void 0},e?.headers])})}delete(s,e={},t){let{betas:r,workspace_id:i}=e??{};return this._client.delete(d`/v1/files/${s}?beta=true`,{...t,headers:l([{...r?.toString()!=null?{"anthropic-beta":r?.toString()}:void 0,...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}download(s,e={},t){let{betas:r,workspace_id:i}=e??{};return this._client.get(d`/v1/files/${s}/content?beta=true`,{...t,headers:l([{Accept:"application/binary",...r?.toString()!=null?{"anthropic-beta":r?.toString()}:void 0,...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers]),__binaryResponse:!0})}retrieveMetadata(s,e={},t){let{betas:r,workspace_id:i}=e??{};return this._client.get(d`/v1/files/${s}?beta=true`,{...t,headers:l([{...r?.toString()!=null?{"anthropic-beta":r?.toString()}:void 0,...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}upload(s,e){let{betas:t,workspace_id:r,...i}=s;return this._client.post("/v1/files?beta=true",ie({body:i,...e,headers:l([{...t?.toString()!=null?{"anthropic-beta":t?.toString()}:void 0,...r!=null?{"anthropic-workspace-id":r}:void 0},wn(i.file),e?.headers])},this._client))}};var it=class extends w{retrieve(s,e={},t){let{betas:r,workspace_id:i}=e??{};return this._client.get(d`/v1/models/${s}?beta=true`,{...t,headers:l([{...r?.toString()!=null?{"anthropic-beta":r?.toString()}:void 0,...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}list(s={},e){let{betas:t,workspace_id:r,...i}=s??{};return this._client.getAPIList("/v1/models?beta=true",W,{query:i,...e,headers:l([{...t?.toString()!=null?{"anthropic-beta":t?.toString()}:void 0,...r!=null?{"anthropic-workspace-id":r}:void 0},e?.headers])})}};var ot=class extends w{create(s,e){let{betas:t,workspace_id:r,...i}=s;return this._client.post("/v1/user_profiles?beta=true",{body:i,...e,headers:l([{"anthropic-beta":[...t??[],"user-profiles-2026-08-18"].toString(),...r!=null?{"anthropic-workspace-id":r}:void 0},e?.headers])})}retrieve(s,e={},t){let{betas:r,workspace_id:i}=e??{};return this._client.get(d`/v1/user_profiles/${s}?beta=true`,{...t,headers:l([{"anthropic-beta":[...r??[],"user-profiles-2026-08-18"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}update(s,e,t){let{betas:r,workspace_id:i,...o}=e;return this._client.post(d`/v1/user_profiles/${s}?beta=true`,{body:o,...t,headers:l([{"anthropic-beta":[...r??[],"user-profiles-2026-08-18"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}list(s={},e){let{betas:t,workspace_id:r,...i}=s??{};return this._client.getAPIList("/v1/user_profiles?beta=true",S,{query:i,...e,headers:l([{"anthropic-beta":[...t??[],"user-profiles-2026-08-18"].toString(),...r!=null?{"anthropic-workspace-id":r}:void 0},e?.headers])})}createEnrollmentURL(s,e={},t){let{betas:r,workspace_id:i}=e??{};return this._client.post(d`/v1/user_profiles/${s}/enrollment_url?beta=true`,{...t,headers:l([{"anthropic-beta":[...r??[],"user-profiles-2026-08-18"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}};var Ko=Ia(zo(),1),ct=class extends w{parseUnverified(s){return JSON.parse(s)}unwrap(s,e){let t=e?.headers;if(t==null)throw new Error("Webhook headers are required in order to verify the signature");let r=e.key===void 0?this._client.webhookKey:e.key;if(!r)throw new Error("Webhook key must not be null or empty in order to unwrap");return new Ko.Webhook(r).verify(s,t),JSON.parse(s)}};var lt=class extends w{list(s,e={},t){let{betas:r,workspace_id:i,...o}=e??{};return this._client.getAPIList(d`/v1/agents/${s}/versions?beta=true`,S,{query:o,...t,headers:l([{"anthropic-beta":[...r??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}};var kn=(()=>{class n extends w{constructor(){super(...arguments),this.versions=new lt(this._client)}create(e,t){let{betas:r,workspace_id:i,...o}=e;return this._client.post("/v1/agents?beta=true",{body:o,...t,headers:l([{"anthropic-beta":[...r??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}retrieve(e,t={},r){let{betas:i,workspace_id:o,...c}=t??{};return this._client.get(d`/v1/agents/${e}?beta=true`,{query:c,...r,headers:l([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...o!=null?{"anthropic-workspace-id":o}:void 0},r?.headers])})}update(e,t,r){let{betas:i,workspace_id:o,...c}=t;return this._client.post(d`/v1/agents/${e}?beta=true`,{body:c,...r,headers:l([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...o!=null?{"anthropic-workspace-id":o}:void 0},r?.headers])})}list(e={},t){let{betas:r,workspace_id:i,...o}=e??{};return this._client.getAPIList("/v1/agents?beta=true",S,{query:o,...t,headers:l([{"anthropic-beta":[...r??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}archive(e,t={},r){let{betas:i,workspace_id:o}=t??{};return this._client.post(d`/v1/agents/${e}/archive?beta=true`,{...r,headers:l([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...o!=null?{"anthropic-workspace-id":o}:void 0},r?.headers])})}}return n.Versions=lt,n})();function Ae(n,s){if(!n)return()=>{};if(n.aborted)return s.abort(),()=>{};let e=()=>s.abort();return n.addEventListener("abort",e),()=>n.removeEventListener("abort",e)}function Re(n,s){return n instanceof B&&n.status===s}function Pc(n){return n instanceof B&&typeof n.status=="number"&&n.status>=400&&n.status<500}function He(n){return Pc(n)&&!Re(n,408)&&!Re(n,409)&&!Re(n,429)}function Sn(n,s,e){return Math.min(s*2**n,e)}function Vo(n,s){return n+Math.random()*(s-n)}function xn(n){return n*(1-Math.random()*.25)}function vn(n,{authToken:s,helper:e}){if(!s)throw new y(`copyClientForHelper: expected a non-empty authToken but received ${JSON.stringify(s)}`);let t=n,r=t._options.defaultHeaders,i=t._authState?.extraHeaders,o=i?Object.fromEntries(Object.entries(i).filter(([h])=>{let u=h.toLowerCase();return u!=="authorization"&&u!=="x-api-key"})):void 0,c=l([o,r,{[Be]:e}]);return n.withOptions({apiKey:null,authToken:s,baseURL:n.baseURL,credentials:void 0,defaultHeaders:c})}var ut,An,oe,Rn,En,Pn,gr,wr,dt,ht,In,ft,br,Ic=999,Tc=1e3,Mc=6e4,Oc=3e5,yr=(()=>{class n{constructor(e){ut.set(this,void 0),An.set(this,!1),oe.set(this,void 0),Rn.set(this,void 0),En.set(this,void 0),Pn.set(this,void 0),gr.set(this,void 0),wr.set(this,void 0),dt.set(this,void 0),this.client=e.client,this.environmentId=e.environmentId,this.environmentKey=e.environmentKey,this.workerId=e.workerId??Nc(),f(this,ut,vn(e.client,{authToken:e.environmentKey,helper:"environments-work-poller"}),"f"),f(this,En,e.autoStop??!0,"f"),f(this,Pn,e.drain??!1,"f"),f(this,gr,e.blockMs===void 0?Ic:e.blockMs,"f"),f(this,wr,e.reclaimOlderThanMs??null,"f"),f(this,dt,e.requestOptions,"f"),f(this,oe,new AbortController,"f"),f(this,Rn,Ae(e.signal,a(this,oe,"f")),"f")}get signal(){return a(this,oe,"f").signal}abort(){a(this,oe,"f").abort()}async*[(ut=new WeakMap,An=new WeakMap,oe=new WeakMap,Rn=new WeakMap,En=new WeakMap,Pn=new WeakMap,gr=new WeakMap,wr=new WeakMap,dt=new WeakMap,Symbol.asyncIterator)](){if(a(this,An,"f"))throw new y("Cannot iterate over a consumed WorkPoller");f(this,An,!0,"f");let e=T(this.client);e.info("poller starting",{component:"work-poller",environment_id:this.environmentId});let t=new $c(e,this.environmentId);try{let r=0;for(;!a(this,oe,"f").signal.aborted;){let i;try{i=await a(this,ut,"f").beta.environments.work.poll(this.environmentId,{"Anthropic-Worker-ID":this.workerId,...a(this,gr,"f")!==null?{block_ms:a(this,gr,"f")}:{},...a(this,wr,"f")!==null?{reclaim_older_than_ms:a(this,wr,"f")}:{}},{headers:l([a(this,dt,"f")?.headers]),signal:a(this,oe,"f").signal})}catch(o){if(a(this,oe,"f").signal.aborted)return;if(He(o))throw e.error("poll failed permanently, stopping poller",{error:String(o)}),o;let c=xn(Cc(r));e.warn("poll failed, backing off",{error:String(o),backoff_ms:c}),r++,await ue(c,a(this,oe,"f").signal);continue}if(r=0,i==null){if(a(this,Pn,"f"))return;t.onEmptyPoll(),await ue(Vo(1e3,3e3),a(this,oe,"f").signal);continue}t.onClaim(),e.info("claimed work",{component:"work-poller",environment_id:this.environmentId,work_id:i.id,work_type:i.data.type});try{await a(this,ut,"f").beta.environments.work.ack(i.id,{environment_id:i.environment_id},{headers:l([a(this,dt,"f")?.headers]),signal:a(this,oe,"f").signal})}catch(o){e.error("ack failed",{work_id:i.id,error:String(o)});continue}try{yield i}finally{if(a(this,En,"f"))try{await a(this,ut,"f").beta.environments.work.stop(i.id,{environment_id:i.environment_id},{headers:l([a(this,dt,"f")?.headers])})}catch(o){Re(o,409)||e.warn("stop failed",{work_id:i.id,error:String(o)})}}}}finally{a(this,Rn,"f").call(this)}}}return n})();function Cc(n){return Sn(n,Tc,Mc)}var $c=(()=>{class n{constructor(e,t){ht.set(this,void 0),In.set(this,void 0),ft.set(this,void 0),br.set(this,0),f(this,ht,e,"f"),f(this,In,t,"f")}onEmptyPoll(){let e=Date.now(),t={component:"work-poller",environment_id:a(this,In,"f")};a(this,ft,"f")===void 0?(f(this,ft,f(this,br,e,"f"),"f"),a(this,ht,"f").info("idle; polling for work",t)):e-a(this,br,"f")>=Oc?(f(this,br,e,"f"),a(this,ht,"f").info(`still polling; idle for ${Math.round((e-a(this,ft,"f"))/1e3)}s`,t)):a(this,ht,"f").debug("poll returned no work",t)}onClaim(){f(this,ft,void 0,"f")}}return ht=new WeakMap,In=new WeakMap,ft=new WeakMap,br=new WeakMap,n})();function Nc(){let s=globalThis.process?.env?.HOSTNAME;return s?`${s}-${ln()}`:ln()}var pt,Ee,mt,Jo=(()=>{class n{constructor(){pt.set(this,[]),Ee.set(this,[]),mt.set(this,!1)}push(e){if(a(this,mt,"f"))return!1;let t=a(this,Ee,"f").shift();return t?t({done:!1,value:e}):a(this,pt,"f").push(e),!0}close(){if(!a(this,mt,"f"))for(f(this,mt,!0,"f");a(this,Ee,"f").length>0;)a(this,Ee,"f").shift()({done:!0,value:void 0})}next(e){return a(this,pt,"f").length>0?Promise.resolve({done:!1,value:a(this,pt,"f").shift()}):a(this,mt,"f")||e?.aborted?Promise.resolve({done:!0,value:void 0}):new Promise(t=>{let r=o=>{e?.removeEventListener("abort",i),t(o)},i=()=>{let o=a(this,Ee,"f").indexOf(r);o>=0&&a(this,Ee,"f").splice(o,1),t({done:!0,value:void 0})};a(this,Ee,"f").push(r),e?.addEventListener("abort",i,{once:!0})})}tryShift(){return a(this,pt,"f").shift()}}return pt=new WeakMap,Ee=new WeakMap,mt=new WeakMap,n})();function ri(n){return"name"in n?n.name:"mcp_server_name"in n?n.mcp_server_name:n.type}function Lc(n){return n instanceof Ge?n.content:`Error: ${n instanceof Error?n.message:String(n)}`}async function Xo(n,s,e){try{let t=n.parse?n.parse(s):s;return{content:await n.run(t,e),isError:!1}}catch(t){return{content:Lc(t),isError:!0}}}var kr,Tn,_t,De,he,H,Mn,z,On,Sr,Cn,q,gt,te,wt,Pe,bt,Se,$n,xr,ae,Nn,Go,Yo,Qo,Zo,ni,ea,Ln,Fn,si,ta,ra;var na=500,Fc=1e4,Bc=12e4,Hc=3e4,Dc=1e3,Wc=3e4,jc=5*6e4,qc=6e4;function sa(n){return n.type==="session.status_idle"&&n.stop_reason?.type==="end_turn"}var Uc=(()=>{class n{constructor(e,t){kr.set(this,void 0),Tn.set(this,void 0),_t.set(this,new Set),De.set(this,!1),he.set(this,void 0),f(this,kr,e,"f"),f(this,Tn,t,"f")}noteEvent(e){e.type!=="user.tool_confirmation"&&(sa(e)?this.arm():this.disarm())}block(e){a(this,_t,"f").add(e),a(this,he,"f")!==void 0&&(f(this,De,!0,"f"),clearTimeout(a(this,he,"f")),f(this,he,void 0,"f"))}unblock(e){a(this,_t,"f").delete(e),a(this,_t,"f").size===0&&a(this,De,"f")&&this.arm()}arm(){if(!(a(this,kr,"f")<=0)){if(a(this,_t,"f").size>0){f(this,De,!0,"f");return}f(this,De,!1,"f"),a(this,he,"f")!==void 0&&clearTimeout(a(this,he,"f")),f(this,he,setTimeout(a(this,Tn,"f"),a(this,kr,"f")),"f")}}disarm(){f(this,De,!1,"f"),a(this,he,"f")!==void 0&&(clearTimeout(a(this,he,"f")),f(this,he,void 0,"f"))}}return kr=new WeakMap,Tn=new WeakMap,_t=new WeakMap,De=new WeakMap,he=new WeakMap,n})(),vr=(()=>{class n{constructor(e,t){H.add(this),Mn.set(this,!1),z.set(this,void 0),On.set(this,void 0),Sr.set(this,void 0),Cn.set(this,void 0),q.set(this,void 0),gt.set(this,new Set),te.set(this,new Set),wt.set(this,new Map),Pe.set(this,new Map),bt.set(this,new Jo),Se.set(this,0),$n.set(this,jc),xr.set(this,null),ae.set(this,void 0),this.client=t.client,this.sessionId=e,this.tools=t.tools,this.maxIdleMs=t.maxIdleMs??qc,f(this,q,T(t.client),"f"),f(this,Cn,new Map(t.tools.map(r=>[ri(r),r])),"f"),f(this,z,new AbortController,"f"),f(this,On,Ae(t.signal,a(this,z,"f")),"f"),f(this,Sr,t.requestOptions,"f"),f(this,ae,new Uc(this.maxIdleMs,()=>{a(this,q,"f").info("session idle after end_turn; stopping",{component:"session-tool-runner",session_id:this.sessionId,max_idle_ms:this.maxIdleMs}),a(this,z,"f").abort()}),"f")}get signal(){return a(this,z,"f").signal}abort(){a(this,z,"f").abort()}_setSendRetryWindow(e){f(this,$n,e,"f")}async*[(Mn=new WeakMap,z=new WeakMap,On=new WeakMap,Sr=new WeakMap,Cn=new WeakMap,q=new WeakMap,gt=new WeakMap,te=new WeakMap,wt=new WeakMap,Pe=new WeakMap,bt=new WeakMap,Se=new WeakMap,$n=new WeakMap,xr=new WeakMap,ae=new WeakMap,H=new WeakSet,Symbol.asyncIterator)](){if(a(this,Mn,"f"))throw new y("Cannot iterate over a consumed SessionToolRunner");f(this,Mn,!0,"f"),a(this,q,"f").info("session tool runner starting",{component:"session-tool-runner",session_id:this.sessionId});let e=a(this,H,"m",Go).call(this).catch(t=>{a(this,z,"f").signal.aborted||a(this,q,"f").error("stream loop failed",{error:String(t)}),a(this,z,"f").abort()});try{for(;;){let r=await a(this,bt,"f").next(a(this,z,"f").signal);if(r.done)break;yield r.value}await e;let t;for(;(t=a(this,bt,"f").tryShift())!==void 0;)yield t}finally{a(this,z,"f").abort(),a(this,ae,"f").disarm(),await e;try{await a(this,H,"m",ra).call(this)}catch(t){a(this,q,"f").warn("drain failed",{error:String(t)})}a(this,bt,"f").close();for(let t of this.tools)try{await t.close?.()}catch(r){a(this,q,"f").warn("tool.close failed",{tool:ri(t),error:String(r)})}a(this,On,"f").call(this)}}}return Nn=function(){return{...a(this,Sr,"f"),headers:l([_n("session-tool-runner"),a(this,Sr,"f")?.headers]),signal:a(this,z,"f").signal}},Go=async function(){let e=a(this,z,"f"),t=na;for(;!e.signal.aborted;){try{let r=await this.client.beta.sessions.events.stream(this.sessionId,{},a(this,H,"m",Nn).call(this));await a(this,H,"m",Yo).call(this);for await(let i of r)if(t=na,await a(this,H,"m",Zo).call(this,i))return}catch(r){if(e.signal.throwIfAborted(),He(r))throw a(this,q,"f").error("permanent stream failure, shutting down",{error:String(r)}),e.abort(),r;a(this,q,"f").warn("stream disconnected, reconnecting",{error:String(r),backoff_ms:t})}e.signal.throwIfAborted(),await ue(t,e.signal),t=Math.min(t*2,Fc)}},Yo=async function(){let e=a(this,z,"f"),t=[],r=!1;try{for await(let c of this.client.beta.sessions.events.list(this.sessionId,{limit:1e3},a(this,H,"m",Nn).call(this)))a(this,H,"m",Qo).call(this,c,t),r=sa(c)}catch(c){e.signal.throwIfAborted(),a(this,q,"f").warn("reconcile list failed",{error:String(c)});for(let h of t)a(this,gt,"f").delete(h.id);return}let i=t.filter(c=>!a(this,te,"f").has(c.id));a(this,ae,"f").disarm();for(let c of i)await a(this,H,"m",ni).call(this,c);for(let c of[...a(this,Pe,"f").values()]){let h=a(this,wt,"f").get(c.id);h!==void 0&&await a(this,H,"m",Ln).call(this,c,h)}let o=i.filter(c=>!a(this,te,"f").has(c.id)&&!a(this,Pe,"f").has(c.id));r&&o.length===0?a(this,ae,"f").arm():a(this,ae,"f").disarm()},Qo=function(e,t){e.type==="agent.tool_use"||e.type==="agent.custom_tool_use"?(a(this,gt,"f").add(e.id),a(this,te,"f").has(e.id)||t.push(e)):e.type==="user.tool_result"?a(this,te,"f").add(e.tool_use_id):e.type==="user.custom_tool_result"?a(this,te,"f").add(e.custom_tool_use_id):e.type==="user.tool_confirmation"&&(a(this,te,"f").has(e.tool_use_id)||a(this,wt,"f").set(e.tool_use_id,e.result))},Zo=async function(e){switch(a(this,ae,"f").noteEvent(e),e.type){case"agent.tool_use":case"agent.custom_tool_use":return a(this,gt,"f").has(e.id)||(a(this,gt,"f").add(e.id),await a(this,H,"m",ni).call(this,e)),!1;case"user.tool_confirmation":return await a(this,H,"m",ea).call(this,e),!1;case"user.tool_result":return a(this,te,"f").add(e.tool_use_id),!1;case"user.custom_tool_result":return a(this,te,"f").add(e.custom_tool_use_id),!1;case"session.status_terminated":case"session.deleted":return a(this,q,"f").info("session terminated",{component:"session-tool-runner",session_id:this.sessionId}),a(this,z,"f").abort(),!0;default:return!1}},ni=async function(e){let t=e.evaluated_permission,r=t==="deny"?"deny":a(this,wt,"f").get(e.id);if(r===void 0){t===void 0||t==="allow"?await a(this,H,"m",si).call(this,e,void 0):a(this,Pe,"f").has(e.id)||(a(this,q,"f").info("tool call awaiting confirmation; holding",{component:"session-tool-runner",session_id:this.sessionId,tool:e.name,tool_use_id:e.id}),a(this,Pe,"f").set(e.id,e),a(this,ae,"f").block(e.id));return}await a(this,H,"m",Ln).call(this,e,r)},ea=async function(e){a(this,wt,"f").set(e.tool_use_id,e.result);let t=a(this,Pe,"f").get(e.tool_use_id);t!==void 0&&await a(this,H,"m",Ln).call(this,t,e.result)},Ln=async function(e,t){let r=a(this,Pe,"f").delete(e.id);if(t==="allow"){a(this,q,"f").info("tool call confirmed",{component:"session-tool-runner",session_id:this.sessionId,tool:e.name,tool_use_id:e.id}),r||a(this,ae,"f").block(e.id);try{await a(this,H,"m",si).call(this,e,"allow")}finally{a(this,ae,"f").unblock(e.id)}return}r&&a(this,ae,"f").unblock(e.id),a(this,te,"f").add(e.id),a(this,q,"f").info("tool call denied; not executing",{component:"session-tool-runner",session_id:this.sessionId,tool:e.name,tool_use_id:e.id}),a(this,H,"m",Fn).call(this,{event:e,toolUseId:e.id,name:e.name,isError:!1,posted:!1,confirmation:"deny"})},Fn=function(e){a(this,bt,"f").push(e)},si=async function(e,t){var r,i;if(!a(this,te,"f").has(e.id)){a(this,q,"f").info("executing tool",{component:"session-tool-runner",session_id:this.sessionId,tool:e.name,tool_use_id:e.id}),f(this,Se,(r=a(this,Se,"f"),r++,r),"f");try{let o=a(this,Cn,"f").get(e.name);if(!o){a(this,q,"f").info("tool not owned by this runner; leaving the tool_use_id pending for its owner",{component:"session-tool-runner",session_id:this.sessionId,tool:e.name,tool_use_id:e.id}),a(this,H,"m",Fn).call(this,{event:e,toolUseId:e.id,name:e.name,isError:!1,posted:!1,confirmation:t});return}let c,h,u=new AbortController,g=Ae(a(this,z,"f").signal,u),p=setTimeout(()=>u.abort(),Bc);try{let _=await Xo(o,e.input,{toolUse:e,toolUseBlock:e,signal:u.signal});c=_.content,h=_.isError}finally{clearTimeout(p),g()}let m=zc(e,h,Kc(c)),b=await a(this,H,"m",ta).call(this,m,e.id);a(this,H,"m",Fn).call(this,{event:e,result:m,toolUseId:e.id,name:e.name,isError:h,posted:b,confirmation:t})}finally{f(this,Se,(i=a(this,Se,"f"),i--,i),"f"),a(this,Se,"f")===0&&a(this,xr,"f")?.call(this)}}},ta=async function(e,t){let r=a(this,z,"f"),i=Date.now(),o,c=0;for(;;){c++,r.signal.throwIfAborted();try{return await this.client.beta.sessions.events.send(this.sessionId,{events:[e]},a(this,H,"m",Nn).call(this)),a(this,te,"f").add(t),!0}catch(h){if(o=h,He(h))break;let u=a(this,$n,"f")-(Date.now()-i);if(u<=0)break;let g=Math.min(xn(Sn(c-1,Dc,Wc)),u);a(this,q,"f").warn("tool result send failed; retrying",{tool_use_id:t,attempt:c,backoff_ms:g,error:String(h)}),await ue(g,r.signal)}}return a(this,q,"f").error("failed to send tool result",{tool_use_id:t,attempts:c,error:String(o)}),!1},ra=async function(){a(this,Se,"f")!==0&&(await Promise.race([new Promise(e=>f(this,xr,e,"f")),ue(Hc)]),f(this,xr,null,"f"),a(this,Se,"f")>0&&a(this,q,"f").warn("drain timeout exceeded"))},n})();function zc(n,s,e){return n.type==="agent.custom_tool_use"?{type:"user.custom_tool_result",custom_tool_use_id:n.id,is_error:s,content:e}:{type:"user.tool_result",tool_use_id:n.id,is_error:s,content:e}}function Kc(n){if(typeof n=="string")return[{type:"text",text:n||"(no output)"}];let s=n.map(e=>e.type==="text"?{type:"text",text:e.text||"(no output)"}:e.type==="image"||e.type==="document"?e:e.type==="search_result"?{type:"search_result",source:e.source,title:e.title,content:e.content.map(t=>({type:"text",text:t.text})),citations:{enabled:e.citations?.enabled??!1}}:{type:"text",text:JSON.stringify(e)});return s.length>0?s:[{type:"text",text:"(no output)"}]}var Bn,Ar,ii,Rr,yt,ia=3e4,Vc=9e4,Jc="NO_HEARTBEAT";function Xc(n){return n.resources.some(s=>s.type==="memory_store")}function Gc(n){if(!n)return null;let s;try{let t=n.replace(/-/g,"+").replace(/_/g,"/"),r=t.padEnd(Math.ceil(t.length/4)*4,"=");s=JSON.parse(cr(po(r)))}catch{return null}if(s===null||typeof s!="object"||Array.isArray(s))return null;let e=s.sessions_token;return typeof e=="string"&&e!==""?e:null}var oi=(()=>{class n{constructor(e){if(Bn.add(this),Ar.set(this,void 0),e.unrestrictedPaths!==void 0)throw new y("The `unrestrictedPaths` option you passed to EnvironmentWorker (or client.beta.environments.work.worker()) is no longer supported. The worker's file tools (read, write, edit, glob, grep) are now always confined to `workdir` plus the session's memory folders. Remove `unrestrictedPaths` from your options; to let the file tools reach any other directory, add it to `AgentToolContext.allowedRoots` from a `tools` factory.");this.client=e.client,this.environmentId=e.environmentId,this.environmentKey=e.environmentKey,this.tools=e.tools,this.workdir=e.workdir??process.cwd(),this.maxFileBytes=e.maxFileBytes,this.maxIdleMs=e.maxIdleMs,e.memorySyncIntervalMs!=null&&Li(e.memorySyncIntervalMs,"memorySyncIntervalMs"),this.memorySyncIntervalMs=e.memorySyncIntervalMs,this.memorySyncDeletions=e.memorySyncDeletions??"enabled",this.workerId=e.workerId,this.requestOptions=e.requestOptions,f(this,Ar,e.signal,"f")}async run(e){let{environmentId:t,environmentKey:r}=this;if(t===void 0||r===void 0)throw new y("EnvironmentWorker.run: environmentId and environmentKey are required to poll for work");let i=e??a(this,Ar,"f"),o=new yr({client:this.client,environmentId:t,environmentKey:r,...this.workerId!==void 0?{workerId:this.workerId}:{},...i?{signal:i}:{},...this.requestOptions!==void 0?{requestOptions:this.requestOptions}:{},autoStop:!1});for await(let c of o)try{await a(this,Bn,"m",ii).call(this,c,r,o.signal)}catch(h){if(o.signal?.aborted)throw h;T(this.client).error("work item failed",{work_id:c.id,error:String(h)})}}async handleItem(e){let t=e?.workId??P("ANTHROPIC_WORK_ID"),r=e?.environmentId??P("ANTHROPIC_ENVIRONMENT_ID"),i=e?.sessionId??P("ANTHROPIC_SESSION_ID"),o=(e?.environmentKey??this.environmentKey??P("ANTHROPIC_ENVIRONMENT_KEY"))||void 0,c=e?.workSecret||P("ANTHROPIC_WORK_SECRET")||null;if(!t)throw new y("handleItem: workId is required \u2014 pass it or set ANTHROPIC_WORK_ID");if(!r)throw new y("handleItem: environmentId is required \u2014 pass it or set ANTHROPIC_ENVIRONMENT_ID");if(!i)throw new y("handleItem: sessionId is required \u2014 pass it or set ANTHROPIC_SESSION_ID");if(!o&&!c)throw new y("handleItem: environmentKey is required when there is no work secret \u2014 pass it, construct the worker with it, or set ANTHROPIC_ENVIRONMENT_KEY");let h={id:t,environment_id:r,secret:c,data:{type:"session",id:i}};await a(this,Bn,"m",ii).call(this,h,o,e?.signal??a(this,Ar,"f"))}}return Ar=new WeakMap,Bn=new WeakSet,ii=async function(e,t,r){let i=T(this.client),o=Gc(e.secret),c=o??t;if(c===void 0)throw new y("handleItem: the work item carried a secret payload but no sessions token could be extracted, and there is no environment key to fall back to; the poller must issue a secret whose payload carries `sessions_token`, or provide the environment key (pass it, construct the worker with it, or set ANTHROPIC_ENVIRONMENT_KEY)");e.secret&&o===null&&i.warn("work item carried a secret payload but no sessions token could be extracted; falling back to the environment key",{work_id:e.id});let h=vn(this.client,{authToken:c,helper:"environments-worker"}),u=e.data.id,g=new AbortController,p=Ae(r,g),m=new Qc(g),b=await import("./node-PTK2HCDV.js"),_,x,A=el(h,e,m,i,this.requestOptions,v=>{_=v,x?._setSendRetryWindow(v)}).catch(v=>{g.signal.aborted||i.error("heartbeat loop failed",{work_id:e.id,error:String(v)}),g.abort()}),E=async()=>{},k,I=!1;try{if(e.data.type!=="session"){i.debug("skipping non-session work item",{work_id:e.id,type:e.data.type});return}let v=await h.beta.sessions.retrieve(u);if(o===null&&this.memorySyncIntervalMs!==null&&Xc(v))throw new b.SessionMemoryError(`cannot mount the session's memories: the work item carried no sessions token (work_id=${e.id}, session_id=${u}); the memory endpoints reject the environment key, so the poller must issue a per-item \`secret\` carrying \`sessions_token\`, or set \`memorySyncIntervalMs: null\` to run without memory`);let R={workdir:this.workdir,client:h,session:v,...this.maxFileBytes!==void 0?{maxFileBytes:this.maxFileBytes}:{}};try{E=await b.setupSkills(R)}catch(M){i.warn("skill setup failed",{session_id:u,work_id:e.id,error:String(M)})}o!==null&&this.memorySyncIntervalMs!==null?(k=new b.SessionMemoryStores(h,{workdir:this.workdir,...this.memorySyncIntervalMs!==void 0?{syncIntervalMs:this.memorySyncIntervalMs}:{},syncDeletions:this.memorySyncDeletions}),await k.download(v),R.allowedRoots=k.roots,R.readOnlyRoots=k.readOnlyRoots):i.debug("memory stores disabled for this item",{work_id:e.id});let C=typeof this.tools=="function"?this.tools(R):this.tools??b.betaAgentToolset20260401(R);x=new vr(u,{client:h,tools:C,...this.maxIdleMs!==void 0?{maxIdleMs:this.maxIdleMs}:{},...this.requestOptions!==void 0?{requestOptions:this.requestOptions}:{},signal:g.signal}),_!==void 0&&x._setSendRetryWindow(_);for await(let M of x)k&&await k.syncIfDue();I=!g.signal.aborted}finally{try{await E().catch(v=>{i.warn("skill cleanup failed",{session_id:u,work_id:e.id,error:String(v)})})}finally{if(k){let v=b.MEMORY_FLUSH_TIMEOUT_MS;I&&await oa(k.finish(),v)&&i.warn(`final memory sync cut off after ${v}ms; the flush that follows still uploads changed files`,{session_id:u,work_id:e.id});let R=new AbortController;await oa(k.flushWrites(R.signal),v)&&(R.abort(),i.warn(`memory flush cut off after ${v}ms; changed files it had not uploaded yet are not saved`,{session_id:u,work_id:e.id})),await k.dispose().catch(M=>{i.warn("memory store cleanup failed",{session_id:u,work_id:e.id,error:String(M)})})}}m.finish("runner_done"),p(),await A,m.lost?i.info("lease lost; released without stopping it",{session_id:u,work_id:e.id}):await Yc(h,e,i,this.requestOptions)}},n})();async function oa(n,s){let e;try{return await Promise.race([n.then(()=>!1,()=>!1),new Promise(t=>{e=setTimeout(()=>t(!0),s)})])}finally{e!==void 0&&clearTimeout(e)}}async function Yc(n,s,e,t){try{await n.beta.environments.work.stop(s.id,{environment_id:s.environment_id,force:!0},{...t,headers:l([t?.headers])})}catch(r){Re(r,409)||e.error("force-stop on exit failed",{work_id:s.id,error:String(r)})}}var Qc=(()=>{class n{constructor(e){Rr.set(this,void 0),yt.set(this,void 0),f(this,Rr,e,"f")}get signal(){return a(this,Rr,"f").signal}finish(e){f(this,yt,a(this,yt,"f")??e,"f"),a(this,Rr,"f").abort()}get lost(){return a(this,yt,"f")==="lease_lost"||a(this,yt,"f")==="assumed_lost"}}return Rr=new WeakMap,yt=new WeakMap,n})();function Zc(n){let s=n instanceof B?n.error:void 0;for(let e of["error","details","current_state"]){if(!Is(s))return{};s=s[e]}return Is(s)?s:{}}async function el(n,s,e,t,r,i){let o=ia,c=Vc,h=Date.now(),u=Jc,g=async()=>{let p=new AbortController,m=Ae(e.signal,p),b=setTimeout(()=>p.abort(),o);try{let _=await n.beta.environments.work.heartbeat(s.id,{environment_id:s.environment_id,expected_last_heartbeat:u},{...r,headers:l([r?.headers]),signal:p.signal});h=Date.now(),u=_.last_heartbeat,_.ttl_seconds>0&&(c=_.ttl_seconds*1e3,o=Math.max(1e3,Math.min(c/2,ia)),i?.(c)),(_.state==="stopping"||_.state==="stopped")&&(t.info("heartbeat signals shutdown",{work_id:s.id,state:_.state}),e.finish("control_plane_stop")),_.lease_extended||(t.warn("lease not extended, shutting down",{work_id:s.id}),e.finish("control_plane_stop"))}catch(_){if(e.signal.throwIfAborted(),Re(_,412)){let x=Zc(_);t.error("lease lost: heartbeat precondition failed",{work_id:s.id,server_state:x.state,server_ttl_seconds:x.ttl_seconds,server_last_heartbeat:x.last_heartbeat}),e.finish("lease_lost");return}if(He(_))throw t.error("permanent heartbeat failure",{work_id:s.id,error:String(_)}),e.finish("heartbeat_rejected"),_;if(Date.now()-h>c){t.error("lease assumed lost: no successful heartbeat in ttl",{work_id:s.id,ttl_ms:c,error:String(_)}),e.finish("assumed_lost");return}t.warn("transient heartbeat failure",{work_id:s.id,error:String(_)})}finally{clearTimeout(b),m()}};for(await g();!e.signal.aborted;)await ue(o,e.signal),e.signal.throwIfAborted(),await g()}var Hn=(()=>{class n extends w{retrieve(e,t,r){let{environment_id:i,betas:o,workspace_id:c}=t;return this._client.get(d`/v1/environments/${i}/work/${e}?beta=true`,{...r,headers:l([{"anthropic-beta":[...o??[],"managed-agents-2026-04-01"].toString(),...c!=null?{"anthropic-workspace-id":c}:void 0},r?.headers])})}update(e,t,r){let{environment_id:i,betas:o,workspace_id:c,...h}=t;return this._client.post(d`/v1/environments/${i}/work/${e}?beta=true`,{body:h,...r,headers:l([{"anthropic-beta":[...o??[],"managed-agents-2026-04-01"].toString(),...c!=null?{"anthropic-workspace-id":c}:void 0},r?.headers])})}list(e,t={},r){let{betas:i,...o}=t??{};return this._client.getAPIList(d`/v1/environments/${e}/work?beta=true`,S,{query:o,...r,headers:l([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString()},r?.headers])})}ack(e,t,r){let{environment_id:i,betas:o}=t;return this._client.post(d`/v1/environments/${i}/work/${e}/ack?beta=true`,{...r,headers:l([{"anthropic-beta":[...o??[],"managed-agents-2026-04-01"].toString()},r?.headers])})}heartbeat(e,t,r){let{environment_id:i,desired_ttl_seconds:o,expected_last_heartbeat:c,betas:h}=t;return this._client.post(d`/v1/environments/${i}/work/${e}/heartbeat?beta=true`,{query:{desired_ttl_seconds:o,expected_last_heartbeat:c},...r,headers:l([{"anthropic-beta":[...h??[],"managed-agents-2026-04-01"].toString()},r?.headers])})}poll(e,t={},r){let{betas:i,"Anthropic-Worker-ID":o,...c}=t??{};return this._client.get(d`/v1/environments/${e}/work/poll?beta=true`,{query:c,...r,headers:l([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...o!=null?{"Anthropic-Worker-ID":o}:void 0},r?.headers])})}stats(e,t={},r){let{betas:i,workspace_id:o}=t??{};return this._client.get(d`/v1/environments/${e}/work/stats?beta=true`,{...r,headers:l([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...o!=null?{"anthropic-workspace-id":o}:void 0},r?.headers])})}stop(e,t,r){let{environment_id:i,betas:o,workspace_id:c,...h}=t;return this._client.post(d`/v1/environments/${i}/work/${e}/stop?beta=true`,{body:h,...r,headers:l([{"anthropic-beta":[...o??[],"managed-agents-2026-04-01"].toString(),...c!=null?{"anthropic-workspace-id":c}:void 0},r?.headers])})}poller(e){return new yr({...e,client:this._client})}worker(e){return new oi({...e,client:this._client})}}return n.WorkPoller=yr,n.EnvironmentWorker=oi,n})();var Dn=(()=>{class n extends w{constructor(){super(...arguments),this.work=new Hn(this._client)}create(e,t){let{betas:r,workspace_id:i,...o}=e;return this._client.post("/v1/environments?beta=true",{body:o,...t,headers:l([{"anthropic-beta":[...r??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}retrieve(e,t={},r){let{betas:i,workspace_id:o}=t??{};return this._client.get(d`/v1/environments/${e}?beta=true`,{...r,headers:l([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...o!=null?{"anthropic-workspace-id":o}:void 0},r?.headers])})}update(e,t,r){let{betas:i,workspace_id:o,...c}=t;return this._client.post(d`/v1/environments/${e}?beta=true`,{body:c,...r,headers:l([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...o!=null?{"anthropic-workspace-id":o}:void 0},r?.headers])})}list(e={},t){let{betas:r,workspace_id:i,...o}=e??{};return this._client.getAPIList("/v1/environments?beta=true",S,{query:o,...t,headers:l([{"anthropic-beta":[...r??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}delete(e,t={},r){let{betas:i,workspace_id:o}=t??{};return this._client.delete(d`/v1/environments/${e}?beta=true`,{...r,headers:l([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...o!=null?{"anthropic-workspace-id":o}:void 0},r?.headers])})}archive(e,t={},r){let{betas:i,workspace_id:o}=t??{};return this._client.post(d`/v1/environments/${e}/archive?beta=true`,{...r,headers:l([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...o!=null?{"anthropic-workspace-id":o}:void 0},r?.headers])})}}return n.Work=Hn,n})();var kt=class extends w{create(s,e,t){let{view:r,betas:i,workspace_id:o,...c}=e;return this._client.post(d`/v1/memory_stores/${s}/memories?beta=true`,{query:{view:r},body:c,...t,headers:l([{"anthropic-beta":[...i??[],"agent-memory-2026-07-22"].toString(),...o!=null?{"anthropic-workspace-id":o}:void 0},t?.headers])})}retrieve(s,e,t){let{memory_store_id:r,betas:i,workspace_id:o,...c}=e;return this._client.get(d`/v1/memory_stores/${r}/memories/${s}?beta=true`,{query:c,...t,headers:l([{"anthropic-beta":[...i??[],"agent-memory-2026-07-22"].toString(),...o!=null?{"anthropic-workspace-id":o}:void 0},t?.headers])})}update(s,e,t){let{memory_store_id:r,view:i,betas:o,workspace_id:c,...h}=e;return this._client.post(d`/v1/memory_stores/${r}/memories/${s}?beta=true`,{query:{view:i},body:h,...t,headers:l([{"anthropic-beta":[...o??[],"agent-memory-2026-07-22"].toString(),...c!=null?{"anthropic-workspace-id":c}:void 0},t?.headers])})}list(s,e={},t){let{betas:r,workspace_id:i,...o}=e??{};return this._client.getAPIList(d`/v1/memory_stores/${s}/memories?beta=true`,S,{query:o,...t,headers:l([{"anthropic-beta":[...r??[],"agent-memory-2026-07-22"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}delete(s,e,t){let{memory_store_id:r,expected_content_sha256:i,betas:o,workspace_id:c}=e;return this._client.delete(d`/v1/memory_stores/${r}/memories/${s}?beta=true`,{query:{expected_content_sha256:i},...t,headers:l([{"anthropic-beta":[...o??[],"agent-memory-2026-07-22"].toString(),...c!=null?{"anthropic-workspace-id":c}:void 0},t?.headers])})}};var St=class extends w{retrieve(s,e,t){let{memory_store_id:r,betas:i,workspace_id:o,...c}=e;return this._client.get(d`/v1/memory_stores/${r}/memory_versions/${s}?beta=true`,{query:c,...t,headers:l([{"anthropic-beta":[...i??[],"agent-memory-2026-07-22"].toString(),...o!=null?{"anthropic-workspace-id":o}:void 0},t?.headers])})}list(s,e={},t){let{betas:r,workspace_id:i,...o}=e??{};return this._client.getAPIList(d`/v1/memory_stores/${s}/memory_versions?beta=true`,S,{query:o,...t,headers:l([{"anthropic-beta":[...r??[],"agent-memory-2026-07-22"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}redact(s,e,t){let{memory_store_id:r,betas:i,workspace_id:o}=e;return this._client.post(d`/v1/memory_stores/${r}/memory_versions/${s}/redact?beta=true`,{...t,headers:l([{"anthropic-beta":[...i??[],"agent-memory-2026-07-22"].toString(),...o!=null?{"anthropic-workspace-id":o}:void 0},t?.headers])})}};var Wn=(()=>{class n extends w{constructor(){super(...arguments),this.memories=new kt(this._client),this.memoryVersions=new St(this._client)}create(e,t){let{betas:r,workspace_id:i,...o}=e;return this._client.post("/v1/memory_stores?beta=true",{body:o,...t,headers:l([{"anthropic-beta":[...r??[],"agent-memory-2026-07-22"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}retrieve(e,t={},r){let{betas:i,workspace_id:o}=t??{};return this._client.get(d`/v1/memory_stores/${e}?beta=true`,{...r,headers:l([{"anthropic-beta":[...i??[],"agent-memory-2026-07-22"].toString(),...o!=null?{"anthropic-workspace-id":o}:void 0},r?.headers])})}update(e,t,r){let{betas:i,workspace_id:o,...c}=t;return this._client.post(d`/v1/memory_stores/${e}?beta=true`,{body:c,...r,headers:l([{"anthropic-beta":[...i??[],"agent-memory-2026-07-22"].toString(),...o!=null?{"anthropic-workspace-id":o}:void 0},r?.headers])})}list(e={},t){let{betas:r,workspace_id:i,...o}=e??{};return this._client.getAPIList("/v1/memory_stores?beta=true",S,{query:o,...t,headers:l([{"anthropic-beta":[...r??[],"agent-memory-2026-07-22"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}delete(e,t={},r){let{betas:i,workspace_id:o}=t??{};return this._client.delete(d`/v1/memory_stores/${e}?beta=true`,{...r,headers:l([{"anthropic-beta":[...i??[],"agent-memory-2026-07-22"].toString(),...o!=null?{"anthropic-workspace-id":o}:void 0},r?.headers])})}archive(e,t={},r){let{betas:i,workspace_id:o}=t??{};return this._client.post(d`/v1/memory_stores/${e}/archive?beta=true`,{...r,headers:l([{"anthropic-beta":[...i??[],"agent-memory-2026-07-22"].toString(),...o!=null?{"anthropic-workspace-id":o}:void 0},r?.headers])})}}return n.Memories=kt,n.MemoryVersions=St,n})();var jn=(()=>{class n{constructor(e,t){this.iterator=e,this.controller=t}async*decoder(){let e=new ur;for await(let t of this.iterator)for(let r of e.decode(t))yield JSON.parse(r);for(let t of e.flush())yield JSON.parse(t)}[Symbol.asyncIterator](){return this.decoder()}static fromResponse(e,t){if(!e.body)throw t.abort(),typeof globalThis.navigator<"u"&&globalThis.navigator.product==="ReactNative"?new y("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 y("Attempted to iterate over a response with no body");return new n(ar(e.body),t)}}return n})();var xt=class extends w{create(s,e){let{betas:t,user_profile_id:r,workspace_id:i,...o}=s;return this._client.post("/v1/messages/batches?beta=true",{body:o,...e,headers:l([{"anthropic-beta":[...t??[],"message-batches-2024-09-24"].toString(),...r!=null?{"anthropic-user-profile-id":r}:void 0,...i!=null?{"anthropic-workspace-id":i}:void 0},e?.headers])})}retrieve(s,e={},t){let{betas:r,workspace_id:i}=e??{};return this._client.get(d`/v1/messages/batches/${s}?beta=true`,{...t,headers:l([{"anthropic-beta":[...r??[],"message-batches-2024-09-24"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}list(s={},e){let{betas:t,workspace_id:r,...i}=s??{};return this._client.getAPIList("/v1/messages/batches?beta=true",W,{query:i,...e,headers:l([{"anthropic-beta":[...t??[],"message-batches-2024-09-24"].toString(),...r!=null?{"anthropic-workspace-id":r}:void 0},e?.headers])})}delete(s,e={},t){let{betas:r,workspace_id:i}=e??{};return this._client.delete(d`/v1/messages/batches/${s}?beta=true`,{...t,headers:l([{"anthropic-beta":[...r??[],"message-batches-2024-09-24"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}cancel(s,e={},t){let{betas:r,workspace_id:i}=e??{};return this._client.post(d`/v1/messages/batches/${s}/cancel?beta=true`,{...t,headers:l([{"anthropic-beta":[...r??[],"message-batches-2024-09-24"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}async results(s,e={},t){let r=await this.retrieve(s,e,t);if(!r.results_url)throw new y(`No batch \`results_url\`; Has it finished processing? ${r.processing_status} - ${r.id}`);let{betas:i,workspace_id:o}=e??{};return this._client.get(r.results_url,{...t,headers:l([{"anthropic-beta":[...i??[],"message-batches-2024-09-24"].toString(),Accept:"application/binary",...o!=null?{"anthropic-workspace-id":o}:void 0},t?.headers]),stream:!0,__binaryResponse:!0})._thenUnwrap((c,h)=>jn.fromResponse(h.response,h.controller))}};var qn={"claude-opus-4@20250514":8192,"anthropic.claude-opus-4-1-20250805-v1:0":8192,"claude-opus-4-1@20250805":8192};function aa(n){return n?.output_format??n?.output_config?.format}function ai(n,s,e){let t=aa(s);return!s||!("parse"in(t??{}))?{...n,content:n.content.map(r=>{if(r.type==="text"){let i=Object.defineProperty({...r},"parsed_output",{value:null,enumerable:!1});return Object.defineProperty(i,"parsed",{get(){return e.logger.warn("The `parsed` property on `text` blocks is deprecated, please use `parsed_output` instead."),null},enumerable:!1})}return r}),parsed_output:null}:ci(n,s,e)}function ci(n,s,e){let t=null,r=n.content.map(i=>{if(i.type==="text"){let o=al(s,i.text);t===null&&(t=o);let c=Object.defineProperty({...i},"parsed_output",{value:o,enumerable:!1});return Object.defineProperty(c,"parsed",{get(){return e.logger.warn("The `parsed` property on `text` blocks is deprecated, please use `parsed_output` instead."),o},enumerable:!1})}return i});return{...n,content:r,parsed_output:t}}function al(n,s){let e=aa(n);if(e?.type!=="json_schema")return null;try{return"parse"in e?e.parse(s):JSON.parse(s)}catch(t){throw new y(`Failed to parse structured output: ${t}`)}}var cl=n=>{let s=0,e=[];for(;s<n.length;){let t=n[s];if(t==="\\"){s++;continue}if(t==="{"){e.push({type:"brace",value:"{"}),s++;continue}if(t==="}"){e.push({type:"brace",value:"}"}),s++;continue}if(t==="["){e.push({type:"paren",value:"["}),s++;continue}if(t==="]"){e.push({type:"paren",value:"]"}),s++;continue}if(t===":"){e.push({type:"separator",value:":"}),s++;continue}if(t===","){e.push({type:"delimiter",value:","}),s++;continue}if(t==='"'){let c=s+1,h=c,u=!1;for(;;){if(h=n.indexOf('"',h),h===-1){u=!0;break}let g=0,p=h-1;for(;p>=c&&n[p]==="\\";)g++,p--;if(g%2===0)break;h++}u?s=n.length:(e.push({type:"string",value:n.slice(c,h)}),s=h+1);continue}if(t&&/\s/.test(t)){s++;continue}let i=/[0-9]/;if(t&&i.test(t)||t==="-"||t==="."){let c="";for(t==="-"&&(c+=t,t=n[++s]);t&&(i.test(t)||t==="."||t==="e"||t==="E"||(t==="-"||t==="+")&&(c[c.length-1]==="e"||c[c.length-1]==="E"));)c+=t,t=n[++s];e.push({type:"number",value:c,unterminated:s===n.length});continue}let o=/[a-z]/i;if(t&&o.test(t)){let c="";for(;t&&o.test(t)&&s!==n.length;)c+=t,t=n[++s];if(c=="true"||c=="false"||c==="null")e.push({type:"name",value:c});else{s++;continue}continue}s++}return e},ll=n=>{let s=[];for(let i of n)(i.type==="brace"||i.type==="paren")&&(i.value==="{"||i.value==="["?s.push(i.value):s.pop());let e=s[s.length-1],t=n.length,r=/^-?(0|[1-9][0-9]*)(\.[0-9]+)?([eE][-+]?[0-9]+)?$/;for(;t>0;){let i=n[t-1];switch(i.type){case"separator":t--;continue;case"number":if(i.unterminated||!r.test(i.value)){t--;continue}break;case"string":let o=n[t-2];if(e==="{"&&(o?.type==="delimiter"||o?.type==="brace"&&o.value==="{")){t--;continue}break;case"delimiter":t--;break}break}return n.slice(0,t)},ul=n=>{let s=[];return n.map(e=>{e.type==="brace"&&(e.value==="{"?s.push("}"):s.splice(s.lastIndexOf("}"),1)),e.type==="paren"&&(e.value==="["?s.push("]"):s.splice(s.lastIndexOf("]"),1))}),s.length>0&&s.reverse().map(e=>{e==="}"?n.push({type:"brace",value:"}"}):e==="]"&&n.push({type:"paren",value:"]"})}),n},dl=n=>{let s="";return n.map(e=>{e.type==="string"?s+='"'+e.value+'"':s+=e.value}),s},ca=n=>JSON.parse(dl(ul(ll(cl(n)))));var Ie="__json_buf";function Un(n,s){let e={};for(let i of Object.keys(n))i!=="input"&&(e[i]=n[i]);Object.defineProperty(e,Ie,{value:s,enumerable:!1,writable:!0});let t,r=!1;return Object.defineProperty(e,"input",{enumerable:!0,configurable:!0,get(){return r||(t=s?ca(s):{},r=!0),t}}),e}var X,Te,vt,Er,zn,Pr,Ir,Kn,Tr,ge,Mr,Vn,Jn,We,Xn,Gn,Yn,Or,li,la,Cr,ui,di,hi,ua,fi;function pi(n){return n.type==="tool_use"||n.type==="server_tool_use"||n.type==="mcp_tool_use"}var Qn=(()=>{class n{constructor(e,t){X.add(this),this.messages=[],this.receivedMessages=[],Te.set(this,void 0),vt.set(this,null),this.controller=new AbortController,Er.set(this,void 0),zn.set(this,()=>{}),Pr.set(this,()=>{}),Ir.set(this,void 0),Kn.set(this,()=>{}),Tr.set(this,()=>{}),ge.set(this,{}),Mr.set(this,!1),Vn.set(this,!1),Jn.set(this,!1),We.set(this,!1),Xn.set(this,void 0),Gn.set(this,void 0),Yn.set(this,void 0),Or.set(this,void 0),Cr.set(this,r=>{if(f(this,Vn,!0,"f"),le(r)&&(r=new K),r instanceof K)return f(this,Jn,!0,"f"),this._emit("abort",r);if(r instanceof y)return this._emit("error",r);if(r instanceof Error){let i=new y(r.message);return i.cause=r,this._emit("error",i)}return this._emit("error",new y(String(r)))}),f(this,Er,new Promise((r,i)=>{f(this,zn,r,"f"),f(this,Pr,i,"f")}),"f"),f(this,Ir,new Promise((r,i)=>{f(this,Kn,r,"f"),f(this,Tr,i,"f")}),"f"),a(this,Er,"f").catch(()=>{}),a(this,Ir,"f").catch(()=>{}),f(this,vt,e,"f"),f(this,Or,t?.logger??console,"f")}get response(){return a(this,Xn,"f")}get request_id(){return a(this,Gn,"f")}get workspace_id(){return a(this,Yn,"f")}async withResponse(){f(this,We,!0,"f");let e=await a(this,Er,"f");if(!e)throw new Error("Could not resolve a `Response` object");return{data:this,response:e,request_id:e.headers.get("request-id"),workspace_id:e.headers.get("anthropic-workspace-id")}}static fromReadableStream(e){let t=new n(null);return t._run(()=>t._fromReadableStream(e)),t}static createMessage(e,t,r,{logger:i}={}){let o=new n(t,{logger:i});for(let c of t.messages)o._addMessageParam(c);return f(o,vt,{...t,stream:!0},"f"),o._run(()=>o._createMessage(e,{...t,stream:!0},{...r,headers:{...r?.headers,[nt]:"stream"}})),o}_run(e){e().then(()=>{this._emitFinal(),this._emit("end")},a(this,Cr,"f"))}_addMessageParam(e){this.messages.push(e)}_addMessage(e,t=!0){this.receivedMessages.push(e),t&&this._emit("message",e)}async _createMessage(e,t,r){let i=r?.signal,o;i&&(i.aborted&&this.controller.abort(),o=this.controller.abort.bind(this.controller),i.addEventListener("abort",o));try{a(this,X,"m",ui).call(this);let{response:c,data:h}=await e.create({...t,stream:!0},{...r,signal:this.controller.signal}).withResponse();this._connected(c);for await(let u of h)a(this,X,"m",di).call(this,u);if(h.controller.signal?.aborted)throw new K;a(this,X,"m",hi).call(this)}finally{i&&o&&i.removeEventListener("abort",o)}}_connected(e){this.ended||(f(this,Xn,e,"f"),f(this,Gn,e?.headers.get("request-id"),"f"),f(this,Yn,e?.headers.get("anthropic-workspace-id"),"f"),a(this,zn,"f").call(this,e),this._emit("connect"))}get ended(){return a(this,Mr,"f")}get errored(){return a(this,Vn,"f")}get aborted(){return a(this,Jn,"f")}abort(){this.controller.abort()}on(e,t){return(a(this,ge,"f")[e]||(a(this,ge,"f")[e]=[])).push({listener:t}),this}off(e,t){let r=a(this,ge,"f")[e];if(!r)return this;let i=r.findIndex(o=>o.listener===t);return i>=0&&r.splice(i,1),this}once(e,t){return(a(this,ge,"f")[e]||(a(this,ge,"f")[e]=[])).push({listener:t,once:!0}),this}emitted(e){return new Promise((t,r)=>{f(this,We,!0,"f"),e!=="error"&&this.once("error",r),this.once(e,t)})}async done(){f(this,We,!0,"f"),await a(this,Ir,"f")}get currentMessage(){return a(this,Te,"f")}async finalMessage(){return await this.done(),a(this,X,"m",li).call(this)}async finalText(){return await this.done(),a(this,X,"m",la).call(this)}_emit(e,...t){if(a(this,Mr,"f"))return;e==="end"&&(f(this,Mr,!0,"f"),a(this,Kn,"f").call(this));let r=a(this,ge,"f")[e];if(r&&(a(this,ge,"f")[e]=r.filter(i=>!i.once),r.forEach(({listener:i})=>i(...t))),e==="abort"){let i=t[0];!a(this,We,"f")&&!r?.length&&Promise.reject(i),a(this,Pr,"f").call(this,i),a(this,Tr,"f").call(this,i),this._emit("end");return}if(e==="error"){let i=t[0];!a(this,We,"f")&&!r?.length&&Promise.reject(i),a(this,Pr,"f").call(this,i),a(this,Tr,"f").call(this,i),this._emit("end")}}_emitFinal(){this.receivedMessages.at(-1)&&this._emit("finalMessage",a(this,X,"m",li).call(this))}async _fromReadableStream(e,t){let r=t?.signal,i;r&&(r.aborted&&this.controller.abort(),i=this.controller.abort.bind(this.controller),r.addEventListener("abort",i));try{a(this,X,"m",ui).call(this),this._connected(null);let o=_e.fromReadableStream(e,this.controller);for await(let c of o)a(this,X,"m",di).call(this,c);if(o.controller.signal?.aborted)throw new K;a(this,X,"m",hi).call(this)}finally{r&&i&&r.removeEventListener("abort",i)}}[(Te=new WeakMap,vt=new WeakMap,Er=new WeakMap,zn=new WeakMap,Pr=new WeakMap,Ir=new WeakMap,Kn=new WeakMap,Tr=new WeakMap,ge=new WeakMap,Mr=new WeakMap,Vn=new WeakMap,Jn=new WeakMap,We=new WeakMap,Xn=new WeakMap,Gn=new WeakMap,Yn=new WeakMap,Or=new WeakMap,Cr=new WeakMap,X=new WeakSet,li=function(){if(this.receivedMessages.length===0)throw new y("stream ended without producing a Message with role=assistant");return this.receivedMessages.at(-1)},la=function(){if(this.receivedMessages.length===0)throw new y("stream ended without producing a Message with role=assistant");let t=this.receivedMessages.at(-1).content.filter(r=>r.type==="text").map(r=>r.text);if(t.length===0)throw new y("stream ended without producing a content block with type=text");return t.join(" ")},ui=function(){this.ended||f(this,Te,void 0,"f")},di=function(t){if(this.ended)return;let r=a(this,X,"m",ua).call(this,t);switch(this._emit("streamEvent",t,r),t.type){case"content_block_delta":{let i=r.content.at(-1);switch(t.delta.type){case"text_delta":{i.type==="text"&&this._emit("text",t.delta.text,i.text||"");break}case"citations_delta":{i.type==="text"&&this._emit("citation",t.delta.citation,i.citations??[]);break}case"input_json_delta":{if(pi(i)&&a(this,ge,"f").inputJson?.length){let o;try{o=i.input}catch(c){a(this,Cr,"f").call(this,a(this,X,"m",fi).call(this,i,c));break}this._emit("inputJson",t.delta.partial_json,o)}break}case"thinking_delta":{i.type==="thinking"&&this._emit("thinking",t.delta.thinking,i.thinking);break}case"signature_delta":{i.type==="thinking"&&this._emit("signature",i.signature);break}case"compaction_delta":{i.type==="compaction"&&i.content&&this._emit("compaction",i.content);break}default:t.delta}break}case"message_stop":{this._addMessageParam(r),this._addMessage(ai(r,a(this,vt,"f"),{logger:a(this,Or,"f")}),!0);break}case"content_block_stop":{this._emit("contentBlock",r.content.at(-1));break}case"message_start":{f(this,Te,r,"f");break}case"content_block_start":case"message_delta":break}},hi=function(){if(this.ended)throw new y("stream has ended, this shouldn't happen");let t=a(this,Te,"f");if(!t)throw new y("request ended without sending any chunks");return f(this,Te,void 0,"f"),ai(t,a(this,vt,"f"),{logger:a(this,Or,"f")})},ua=function(t){let r=a(this,Te,"f");if(t.type==="message_start"){if(r)throw new y(`Unexpected event order, got ${t.type} before receiving "message_stop"`);return t.message}if(!r)throw new y(`Unexpected event order, got ${t.type} before "message_start"`);switch(t.type){case"message_stop":return r;case"message_delta":return r.stop_reason=t.delta.stop_reason,r.stop_sequence=t.delta.stop_sequence,r.stop_details=t.delta.stop_details,r.usage.output_tokens=t.usage.output_tokens,t.delta.container!=null&&(r.container=t.delta.container),t.context_management!=null&&(r.context_management=t.context_management),t.input_transformations!=null&&(r.input_transformations=t.input_transformations),t.usage.input_tokens!=null&&(r.usage.input_tokens=t.usage.input_tokens),t.usage.cache_creation_input_tokens!=null&&(r.usage.cache_creation_input_tokens=t.usage.cache_creation_input_tokens),t.usage.cache_read_input_tokens!=null&&(r.usage.cache_read_input_tokens=t.usage.cache_read_input_tokens),t.usage.server_tool_use!=null&&(r.usage.server_tool_use=t.usage.server_tool_use),t.usage.iterations!=null&&(r.usage.iterations=t.usage.iterations),t.usage.fallback_credit!=null&&(r.usage.fallback_credit=t.usage.fallback_credit),t.usage.output_tokens_details!=null&&(r.usage.output_tokens_details=t.usage.output_tokens_details),r;case"content_block_start":return r.content.push(t.content_block),t.content_block.type==="fallback"&&(r.model=t.content_block.to.model),r;case"content_block_delta":{let i=r.content.at(t.index);switch(t.delta.type){case"text_delta":{i?.type==="text"&&(r.content[t.index]={...i,text:(i.text||"")+t.delta.text});break}case"citations_delta":{i?.type==="text"&&(r.content[t.index]={...i,citations:[...i.citations??[],t.delta.citation]});break}case"input_json_delta":{if(i&&pi(i)){let o=(i[Ie]||"")+t.delta.partial_json;r.content[t.index]=Un(i,o)}break}case"thinking_delta":{i?.type==="thinking"&&(r.content[t.index]={...i,thinking:i.thinking+t.delta.thinking});break}case"signature_delta":{i?.type==="thinking"&&(r.content[t.index]={...i,signature:t.delta.signature});break}case"compaction_delta":{if(i?.type==="compaction"){let o={...i,content:t.delta.content};"encrypted_content"in t.delta&&(o.encrypted_content=t.delta.encrypted_content),r.content[t.index]=o}break}default:t.delta}return r}case"content_block_stop":{let i=r.content.at(t.index);if(i&&pi(i)&&Ie in i){let o;try{o=i.input}catch(c){o={},a(this,Cr,"f").call(this,a(this,X,"m",fi).call(this,i,c))}Object.defineProperty(i,"input",{value:o,enumerable:!0,configurable:!0,writable:!0})}return r}}},fi=function(t,r){let i=t[Ie];return new y(`Unable to parse tool parameter JSON from model. Please retry your request or adjust your prompt. Error: ${r}. JSON: ${i}`)},Symbol.asyncIterator)](){let e=[],t=[],r=!1;return this.on("streamEvent",i=>{let o=t.shift();o?o.resolve(i):e.push(i)}),this.on("end",()=>{r=!0;for(let i of t)i.resolve(void 0);t.length=0}),this.on("abort",i=>{r=!0;for(let o of t)o.reject(i);t.length=0}),this.on("error",i=>{r=!0;for(let o of t)o.reject(i);t.length=0}),{next:async()=>e.length?{value:e.shift(),done:!1}:r?{value:void 0,done:!0}:new Promise((o,c)=>t.push({resolve:o,reject:c})).then(o=>o?{value:o,done:!1}:{value:void 0,done:!0}),return:async()=>(this.abort(),{value:void 0,done:!0})}}toReadableStream(){return new _e(this[Symbol.asyncIterator].bind(this),this.controller).toReadableStream()}}return n})();var xe,Zn,je,At,es,qe,Rt,ts,da,rs,ns,mi=(()=>{class n extends Qn{constructor(e,t){super(e),xe.add(this),Zn.set(this,void 0),je.set(this,0),At.set(this,[]),es.set(this,[]),qe.set(this,void 0),Rt.set(this,[]),ts.set(this,!1),f(this,Zn,t,"f")}get toolCalls(){return a(this,es,"f")}static start(e,t,r,i){let o=new n({...t,stream:!0},i);for(let c of t.messages)o._addMessageParam(c);return o._run(()=>o._createMessage(e,{...t,stream:!0},{...r,headers:{...r?.headers,[nt]:"stream"}})),o}_emit(e,...t){var r;if(e!=="streamEvent"||this.ended){super._emit(e,...t);return}f(this,je,(r=a(this,je,"f"),r++,r),"f");let[i,o]=t,c=i.type==="content_block_stop"?o.content[i.index]:void 0,h=c?.type==="tool_use"?c:void 0;h&&a(this,es,"f").push(h),super._emit(e,...t),a(this,xe,"m",da).call(this,i,h),a(this,xe,"m",rs).call(this)}[(Zn=new WeakMap,je=new WeakMap,At=new WeakMap,es=new WeakMap,qe=new WeakMap,Rt=new WeakMap,ts=new WeakMap,xe=new WeakSet,Symbol.asyncIterator)](){let e=super[Symbol.asyncIterator](),t={handled:a(this,je,"f")};a(this,At,"f").push(t);let r=!1;return{next:async()=>{r&&(r=!1,t.handled++,a(this,xe,"m",rs).call(this));try{let i=await e.next();return r=!i.done,i.done&&a(this,xe,"m",ns).call(this,t),i}catch(i){throw a(this,xe,"m",ns).call(this,t),i}},return:async()=>{let i=e.return?.();return a(this,xe,"m",ns).call(this,t),await i??{value:void 0,done:!0}}}}}return da=function(e,t){if(a(this,ts,"f"))return;if(e.type==="content_block_start"&&e.content_block.type==="fallback"){f(this,ts,!0,"f"),f(this,qe,void 0,"f");return}let r=e.type==="content_block_start"||e.type==="message_delta"&&e.delta.stop_reason==="tool_use";a(this,qe,"f")&&r&&(a(this,Rt,"f").push({toolUse:a(this,qe,"f"),event:a(this,je,"f")}),f(this,qe,void 0,"f")),t&&f(this,qe,t,"f")},rs=function(){if(this.errored||this.controller.signal.aborted)return;let e=Math.min(a(this,je,"f"),...a(this,At,"f").map(t=>t.handled));for(;a(this,Rt,"f")[0]&&a(this,Rt,"f")[0].event<=e;)a(this,Zn,"f").call(this,a(this,Rt,"f").shift().toolUse)},ns=function(e){let t=a(this,At,"f").indexOf(e);t>=0&&(a(this,At,"f").splice(t,1),a(this,xe,"m",rs).call(this))},n})();var L,Et,Ue,N,G,Y,Me,we,Oe,$r,re,be,Pt,It,ze,_i,ha,gi,wi,Nr,ss,fa,bi,yi,pa,ki,xi=(()=>{class n{constructor(e,t,r){L.add(this),this.client=e,Et.set(this,!1),Ue.set(this,!1),N.set(this,void 0),G.set(this,void 0),Y.set(this,void 0),Me.set(this,void 0),we.set(this,void 0),Oe.set(this,void 0),$r.set(this,0),re.set(this,{status:"idle"}),be.set(this,void 0),Pt.set(this,null),It.set(this,new Map),ze.set(this,[]),ma(t),hl(t),_a(t),f(this,N,{params:{...t,messages:JSON.parse(JSON.stringify(t.messages))}},"f");let i=Qs(t.tools,t.messages);f(this,G,{...r,headers:l([_n("BetaToolRunner"),i.length?{[Be]:i.join(", ")}:void 0,r?.headers])},"f"),f(this,Oe,Rs(),"f")}async*[(Et=new WeakMap,Ue=new WeakMap,N=new WeakMap,G=new WeakMap,Y=new WeakMap,Me=new WeakMap,we=new WeakMap,Oe=new WeakMap,$r=new WeakMap,re=new WeakMap,be=new WeakMap,Pt=new WeakMap,It=new WeakMap,ze=new WeakMap,L=new WeakSet,Symbol.asyncIterator)](){var e;if(a(this,Et,"f"))throw new y("Cannot iterate over a consumed stream");f(this,Et,!0,"f"),f(this,Ue,!0,"f"),f(this,we,void 0,"f");try{for(;;)try{if(a(this,N,"f").params.max_iterations&&a(this,$r,"f")>=a(this,N,"f").params.max_iterations)break;if(a(this,L,"m",pa).call(this),a(this,re,"f").status==="scheduled"&&wa(a(this,Pt,"f"))!=="resume"){yield*a(this,L,"m",wi).call(this,a(this,re,"f").config);continue}f(this,Ue,!1,"f"),f(this,we,void 0,"f"),f(this,$r,(e=a(this,$r,"f"),e++,e),"f"),f(this,Y,void 0,"f");let{max_iterations:t,runToolsEagerly:r,...i}=a(this,N,"f").params;if(yield*a(this,L,"m",_i).call(this,i),a(this,Ue,"f"))f(this,Pt,null,"f");else{let c=await a(this,Y,"f"),h=wa(c.stop_reason);f(this,Pt,c.stop_reason,"f"),a(this,N,"f").params.messages.push({role:c.role,content:c.content});let{container:u}=a(this,N,"f").params;if(c.container&&(u==null?a(this,N,"f").params.container=c.container.id:typeof u=="object"&&u.id==null&&(a(this,N,"f").params.container={...u,id:c.container.id})),h==="stop"){yield*a(this,L,"m",bi).call(this);break}if(h==="resume")continue}let o=await a(this,L,"m",yi).call(this,a(this,N,"f").params.messages.at(-1));if(o)a(this,N,"f").params.messages.push(o);else if(!a(this,Ue,"f")){yield*a(this,L,"m",bi).call(this);break}}finally{a(this,Me,"f")?.abort(),f(this,Me,void 0,"f")}if(await a(this,L,"m",gi).call(this),!a(this,Y,"f"))throw new y("ToolRunner concluded without a message from the server");a(this,Oe,"f").resolve(await a(this,Y,"f"))}catch(t){throw f(this,Et,!1,"f"),a(this,Oe,"f").promise.catch(()=>{}),a(this,Oe,"f").reject(t),f(this,Oe,Rs(),"f"),t}}setMessagesParams(e){let t=typeof e=="function"?e(a(this,N,"f").params):e;if(ma(t),_a(t),a(this,re,"f").status!=="idle"&&Si(t),a(this,re,"f").status==="in_flight"&&t.messages!==a(this,N,"f").params.messages)throw new y("Message params can't be changed while the conversation is being compacted, because the compaction response is about to replace them. Change them after this iteration instead.");a(this,N,"f").params=t,f(this,Ue,!0,"f"),f(this,we,void 0,"f")}setRequestOptions(e){typeof e=="function"?f(this,G,e(a(this,G,"f")),"f"):f(this,G,{...a(this,G,"f"),...e},"f")}async generateToolResponse(e=a(this,G,"f").signal){let t=await a(this,Y,"f")??this.params.messages.at(-1);return t?a(this,L,"m",yi).call(this,t,e):null}deferToolCall(e){let t=typeof e=="string"?e:e.id;a(this,be,"f")&&!a(this,be,"f").has(t)&&a(this,be,"f").set(t,{status:"held"})}get deferredToolCalls(){let e=a(this,Me,"f"),t=a(this,be,"f");return!(e instanceof mi)||!t?[]:e.toolCalls.filter(r=>t.get(r.id)?.status==="held")}done(){return a(this,Oe,"f").promise}async runUntilDone(){if(!a(this,Et,"f"))for await(let e of this);return this.done()}get params(){return a(this,N,"f").params}pushMessages(...e){this.setMessagesParams(t=>({...t,messages:[...t.messages,...e]}))}compactBeforeNextTurn(e){a(this,re,"f").status!=="in_flight"&&(Si(a(this,N,"f").params),f(this,re,{status:"scheduled",config:e??{type:"summarize"}},"f"))}addTools(...e){for(let t of e)"name"in t&&a(this,It,"f").set(t.name,"run"in t?t:null),a(this,ze,"f").push({type:"addition",tool:t})}removeTools(...e){for(let t of e){let r=typeof t=="string"?t:t.name;a(this,It,"f").set(r,null),a(this,ze,"f").push({type:"removal",name:r})}}then(e,t){return this.runUntilDone().then(e,t)}}return _i=async function*(e){await a(this,L,"m",gi).call(this),f(this,be,void 0,"f"),e.stream?(f(this,Me,a(this,N,"f").params.runToolsEagerly?a(this,L,"m",ha).call(this,e):this.client.beta.messages.stream({...e},a(this,G,"f")),"f"),f(this,Y,a(this,Me,"f").finalMessage(),"f"),a(this,Y,"f").catch(()=>{}),yield a(this,Me,"f")):(f(this,Y,this.client.beta.messages.create({...e,stream:!1},a(this,G,"f")),"f"),yield a(this,Y,"f"))},ha=function(e){let t=new Map;return f(this,be,t,"f"),mi.start(this.client.beta.messages,e,a(this,G,"f"),r=>{if(t.has(r.id))return;let i=ba(a(this,L,"m",Nr).call(this),a(this,L,"m",ss).call(this),r,a(this,G,"f"));i.catch(()=>{}),t.set(r.id,{status:"started",result:i})})},gi=async function(){let e=[...a(this,be,"f")?.values()??[]].filter(t=>t.status==="started");await Promise.allSettled(e.map(t=>t.result))},wi=async function*(e){Si(a(this,N,"f").params);let{max_iterations:t,runToolsEagerly:r,...i}=a(this,N,"f").params,o=fl(i);f(this,re,{status:"in_flight"},"f"),f(this,we,void 0,"f");let c=a(this,Y,"f");try{yield*a(this,L,"m",_i).call(this,{...o,compaction:e});let h=await a(this,Y,"f");h.content.some(u=>u.type==="compaction"&&u.content)?(a(this,L,"m",fa).call(this),a(this,N,"f").params.messages=[{role:h.role,content:h.content}]):(T(this.client).warn("Compaction produced no summary; keeping the conversation as it is."),f(this,Y,c,"f"))}finally{f(this,re,{status:"idle"},"f")}},Nr=function(){let e=new Map;for(let t of a(this,N,"f").params.tools)"run"in t&&e.set(t.name,t);for(let[t,r]of a(this,It,"f"))r?e.set(t,r):e.delete(t);return e},ss=function(){let e=new Set(a(this,L,"m",Nr).call(this).keys());for(let t of[...a(this,N,"f").params.messages,a(this,L,"m",ki).call(this)])if(typeof t.content!="string"){for(let r of t.content)if(t.role==="system")ga(r,e);else if(t.role==="assistant"&&r.type==="compaction")for(let i of r.tool_changes??[])ga(i,e)}return e},fa=function(){let e=a(this,L,"m",ss).call(this);for(let t of a(this,L,"m",Nr).call(this).keys())e.has(t)||a(this,It,"f").set(t,null)},bi=async function*(){if(a(this,re,"f").status!=="scheduled")return;let e=a(this,N,"f").params.messages.at(-1)?.content;if(Array.isArray(e)&&e.some(t=>t.type==="tool_use")){T(this.client).warn("The pending compaction was skipped because the last turn ended with tool calls that were not run. Call `compactBeforeNextTurn()` again if you continue the conversation."),f(this,re,{status:"idle"},"f");return}yield*a(this,L,"m",wi).call(this,a(this,re,"f").config)},yi=async function(e,t=a(this,G,"f").signal){return a(this,we,"f")!==void 0?a(this,we,"f"):(f(this,we,pl(a(this,L,"m",Nr).call(this),a(this,L,"m",ss).call(this),e,{...a(this,G,"f"),signal:t},a(this,be,"f")),"f"),a(this,we,"f"))},pa=function(){a(this,Pt,"f")==="pause_turn"||a(this,ze,"f").length===0||(a(this,N,"f").params.messages.push(a(this,L,"m",ki).call(this)),f(this,ze,[],"f"))},ki=function(){let e=[];for(let t of a(this,ze,"f")){if(t.type==="removal"){e.push({type:"tool_removal",tool:{type:"tool_reference",name:t.name}});continue}let r=t.tool;if("run"in t.tool){let{run:i,parse:o,close:c,...h}=t.tool;r=h}e.push({type:"tool_addition",tool:{type:"tool_definition",definition:r}})}return{role:"system",content:e}},n})();function ma(n){if("compaction"in n&&n.compaction!=null)throw new y("`compaction` cannot be set on a tool runner: every request in the loop would compact again. Call `runner.compactBeforeNextTurn()` when the conversation should be compacted instead.")}function hl(n){if("compactionControl"in n&&n.compactionControl!=null)throw new y("`compactionControl` has been removed from the tool runner. Use server-side compaction instead: call `runner.compactBeforeNextTurn()` when the conversation should be compacted.")}function _a(n){if(n.runToolsEagerly&&!n.stream)throw new TypeError("`runToolsEagerly: true` needs `stream: true` in the tool runner's params, because a reply that isn't streamed arrives whole.")}function Si(n){if(n.context_management?.edits?.some(s=>s.type.startsWith("compact_")))throw new y("`compactBeforeNextTurn()` can't be used while `context_management` has a compaction edit, because the API doesn't accept a compaction block together with one. Remove the edit first.")}function fl(n){let{context_management:s,stop_sequences:e,output_format:t,...r}=n,i=({format:o,...c})=>c;return(r.tool_choice?.type==="any"||r.tool_choice?.type==="tool")&&delete r.tool_choice,r.output_config&&(r.output_config=i(r.output_config)),Array.isArray(r.fallbacks)&&(r.fallbacks=r.fallbacks.map(o=>o.output_config?{...o,output_config:i(o.output_config)}:o)),r}async function pl(n,s,e,t,r){if(!e||e.role!=="assistant"||!e.content||typeof e.content=="string")return null;let i=e.content.filter(c=>c.type==="tool_use");return i.length===0?null:{role:"user",content:await Promise.all(i.map(c=>{let h=r?.get(c.id);if(h?.status==="started")return h.result;let u=ba(n,s,c,t);return r?.set(c.id,{status:"started",result:u}),u}))}}async function ba(n,s,e,t){let r=s.has(e.name)?n.get(e.name):void 0;if(!r)return ml(e);try{let i=e.input;"parse"in r&&r.parse&&(i=r.parse(i));let o=await r.run(i,{toolUse:e,toolUseBlock:e,signal:t?.signal});return{type:"tool_result",tool_use_id:e.id,content:o}}catch(i){return{type:"tool_result",tool_use_id:e.id,content:i instanceof Ge?i.content:`Error: ${i instanceof Error?i.message:String(i)}`,is_error:!0}}}function ml(n){return{type:"tool_result",tool_use_id:n.id,content:`Error: Tool '${n.name}' not found`,is_error:!0}}function ga(n,s){switch(n.type){case"tool_removal":case"tool_addition":_l(n,s);break}}function _l(n,s){let e=gl(n.tool);e!==void 0&&(n.type==="tool_removal"?s.delete(e):s.add(e))}function gl(n){switch(n.type){case"tool_reference":return n.name;case"tool_definition":return"name"in n.definition?n.definition.name:void 0;default:return}}function wa(n){if(n===null)return"stop";switch(n){case"tool_use":return"run_tools";case"pause_turn":case"compaction":return"resume";case"end_turn":case"stop_sequence":case"max_tokens":case"model_context_window_exceeded":case"refusal":return"stop";default:return"stop"}}var ya={},wl=["claude-mythos-preview","claude-opus-4-6"],is=(()=>{class n extends w{constructor(){super(...arguments),this.batches=new xt(this._client)}create(e,t){let r=ka(e),{betas:i,user_profile_id:o,workspace_id:c,...h}=r;h.model in ya&&console.warn(`The model '${h.model}' is deprecated and will reach end-of-life on ${ya[h.model]}
|
|
12
|
+
${p}`)}return o},d=uc(No);var Ze=class extends w{retrieve(s,e={},t){let{betas:r,workspace_id:i}=e??{};return this._client.get(d`/v1/deployment_runs/${s}?beta=true`,{...t,headers:l([{"anthropic-beta":[...r??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}list(s={},e){let{betas:t,workspace_id:r,...i}=s??{};return this._client.getAPIList("/v1/deployment_runs?beta=true",S,{query:i,...e,headers:l([{"anthropic-beta":[...t??[],"managed-agents-2026-04-01"].toString(),...r!=null?{"anthropic-workspace-id":r}:void 0},e?.headers])})}};var et=class extends w{create(s,e){let{betas:t,workspace_id:r,...i}=s;return this._client.post("/v1/deployments?beta=true",{body:i,...e,headers:l([{"anthropic-beta":[...t??[],"managed-agents-2026-04-01"].toString(),...r!=null?{"anthropic-workspace-id":r}:void 0},e?.headers])})}retrieve(s,e={},t){let{betas:r,workspace_id:i}=e??{};return this._client.get(d`/v1/deployments/${s}?beta=true`,{...t,headers:l([{"anthropic-beta":[...r??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}update(s,e,t){let{betas:r,workspace_id:i,...o}=e;return this._client.post(d`/v1/deployments/${s}?beta=true`,{body:o,...t,headers:l([{"anthropic-beta":[...r??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}list(s={},e){let{betas:t,workspace_id:r,...i}=s??{};return this._client.getAPIList("/v1/deployments?beta=true",S,{query:i,...e,headers:l([{"anthropic-beta":[...t??[],"managed-agents-2026-04-01"].toString(),...r!=null?{"anthropic-workspace-id":r}:void 0},e?.headers])})}archive(s,e={},t){let{betas:r,workspace_id:i}=e??{};return this._client.post(d`/v1/deployments/${s}/archive?beta=true`,{...t,headers:l([{"anthropic-beta":[...r??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}pause(s,e={},t){let{betas:r,workspace_id:i}=e??{};return this._client.post(d`/v1/deployments/${s}/pause?beta=true`,{...t,headers:l([{"anthropic-beta":[...r??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}run(s,e={},t){let{betas:r,workspace_id:i}=e??{};return this._client.post(d`/v1/deployments/${s}/run?beta=true`,{...t,headers:l([{"anthropic-beta":[...r??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}unpause(s,e={},t){let{betas:r,workspace_id:i}=e??{};return this._client.post(d`/v1/deployments/${s}/unpause?beta=true`,{...t,headers:l([{"anthropic-beta":[...r??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}};var tt=class extends w{create(s,e){let{betas:t,workspace_id:r,...i}=s;return this._client.post("/v1/dreams?beta=true",{body:i,...e,headers:l([{"anthropic-beta":[...t??[],"dreaming-2026-04-21"].toString(),...r!=null?{"anthropic-workspace-id":r}:void 0},e?.headers])})}retrieve(s,e={},t){let{betas:r,workspace_id:i}=e??{};return this._client.get(d`/v1/dreams/${s}?beta=true`,{...t,headers:l([{"anthropic-beta":[...r??[],"dreaming-2026-04-21"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}list(s={},e){let{betas:t,workspace_id:r,...i}=s??{};return this._client.getAPIList("/v1/dreams?beta=true",S,{query:i,...e,headers:l([{"anthropic-beta":[...t??[],"dreaming-2026-04-21"].toString(),...r!=null?{"anthropic-workspace-id":r}:void 0},e?.headers])})}archive(s,e={},t){let{betas:r,workspace_id:i}=e??{};return this._client.post(d`/v1/dreams/${s}/archive?beta=true`,{...t,headers:l([{"anthropic-beta":[...r??[],"dreaming-2026-04-21"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}cancel(s,e={},t){let{betas:r,workspace_id:i}=e??{};return this._client.post(d`/v1/dreams/${s}/cancel?beta=true`,{...t,headers:l([{"anthropic-beta":[...r??[],"dreaming-2026-04-21"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}};var Be="x-stainless-helper",nt="x-stainless-helper-method";function _n(n){return{[Be]:n}}var rt=Symbol("anthropic.sdk.stainlessHelper");function mr(n){return typeof n=="object"&&n!==null&&rt in n}function Qs(n,s){let e=new Set;if(n)for(let t of n)mr(t)&&e.add(t[rt]);if(s)for(let t of s){mr(t)&&e.add(t[rt]);let r=t.content;if(Array.isArray(r))for(let i of r){mr(i)&&e.add(i[rt]);let o=i?.tool?.definition;mr(o)&&e.add(o[rt])}}return Array.from(e)}function gn(n,s){let e=Qs(n,s);return e.length===0?{}:{[Be]:e.join(", ")}}function wn(n){return mr(n)?{[Be]:n[rt]}:{}}var st=class extends w{list(s={},e){let{betas:t,workspace_id:r,...i}=s??{};return this._client.getAPIList("/v1/files?beta=true",S,{query:i,...e,headers:l([{...t?.toString()!=null?{"anthropic-beta":t?.toString()}:void 0,...r!=null?{"anthropic-workspace-id":r}:void 0},e?.headers])})}delete(s,e={},t){let{betas:r,workspace_id:i}=e??{};return this._client.delete(d`/v1/files/${s}?beta=true`,{...t,headers:l([{...r?.toString()!=null?{"anthropic-beta":r?.toString()}:void 0,...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}download(s,e={},t){let{betas:r,workspace_id:i}=e??{};return this._client.get(d`/v1/files/${s}/content?beta=true`,{...t,headers:l([{Accept:"application/binary",...r?.toString()!=null?{"anthropic-beta":r?.toString()}:void 0,...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers]),__binaryResponse:!0})}retrieveMetadata(s,e={},t){let{betas:r,workspace_id:i}=e??{};return this._client.get(d`/v1/files/${s}?beta=true`,{...t,headers:l([{...r?.toString()!=null?{"anthropic-beta":r?.toString()}:void 0,...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}upload(s,e){let{betas:t,workspace_id:r,...i}=s;return this._client.post("/v1/files?beta=true",ie({body:i,...e,headers:l([{...t?.toString()!=null?{"anthropic-beta":t?.toString()}:void 0,...r!=null?{"anthropic-workspace-id":r}:void 0},wn(i.file),e?.headers])},this._client))}};var it=class extends w{retrieve(s,e={},t){let{betas:r,workspace_id:i}=e??{};return this._client.get(d`/v1/models/${s}?beta=true`,{...t,headers:l([{...r?.toString()!=null?{"anthropic-beta":r?.toString()}:void 0,...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}list(s={},e){let{betas:t,workspace_id:r,...i}=s??{};return this._client.getAPIList("/v1/models?beta=true",W,{query:i,...e,headers:l([{...t?.toString()!=null?{"anthropic-beta":t?.toString()}:void 0,...r!=null?{"anthropic-workspace-id":r}:void 0},e?.headers])})}};var ot=class extends w{create(s,e){let{betas:t,workspace_id:r,...i}=s;return this._client.post("/v1/user_profiles?beta=true",{body:i,...e,headers:l([{"anthropic-beta":[...t??[],"user-profiles-2026-08-18"].toString(),...r!=null?{"anthropic-workspace-id":r}:void 0},e?.headers])})}retrieve(s,e={},t){let{betas:r,workspace_id:i}=e??{};return this._client.get(d`/v1/user_profiles/${s}?beta=true`,{...t,headers:l([{"anthropic-beta":[...r??[],"user-profiles-2026-08-18"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}update(s,e,t){let{betas:r,workspace_id:i,...o}=e;return this._client.post(d`/v1/user_profiles/${s}?beta=true`,{body:o,...t,headers:l([{"anthropic-beta":[...r??[],"user-profiles-2026-08-18"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}list(s={},e){let{betas:t,workspace_id:r,...i}=s??{};return this._client.getAPIList("/v1/user_profiles?beta=true",S,{query:i,...e,headers:l([{"anthropic-beta":[...t??[],"user-profiles-2026-08-18"].toString(),...r!=null?{"anthropic-workspace-id":r}:void 0},e?.headers])})}createEnrollmentURL(s,e={},t){let{betas:r,workspace_id:i}=e??{};return this._client.post(d`/v1/user_profiles/${s}/enrollment_url?beta=true`,{...t,headers:l([{"anthropic-beta":[...r??[],"user-profiles-2026-08-18"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}};var Ko=Ia(zo(),1),ct=class extends w{parseUnverified(s){return JSON.parse(s)}unwrap(s,e){let t=e?.headers;if(t==null)throw new Error("Webhook headers are required in order to verify the signature");let r=e.key===void 0?this._client.webhookKey:e.key;if(!r)throw new Error("Webhook key must not be null or empty in order to unwrap");return new Ko.Webhook(r).verify(s,t),JSON.parse(s)}};var lt=class extends w{list(s,e={},t){let{betas:r,workspace_id:i,...o}=e??{};return this._client.getAPIList(d`/v1/agents/${s}/versions?beta=true`,S,{query:o,...t,headers:l([{"anthropic-beta":[...r??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}};var kn=(()=>{class n extends w{constructor(){super(...arguments),this.versions=new lt(this._client)}create(e,t){let{betas:r,workspace_id:i,...o}=e;return this._client.post("/v1/agents?beta=true",{body:o,...t,headers:l([{"anthropic-beta":[...r??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}retrieve(e,t={},r){let{betas:i,workspace_id:o,...c}=t??{};return this._client.get(d`/v1/agents/${e}?beta=true`,{query:c,...r,headers:l([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...o!=null?{"anthropic-workspace-id":o}:void 0},r?.headers])})}update(e,t,r){let{betas:i,workspace_id:o,...c}=t;return this._client.post(d`/v1/agents/${e}?beta=true`,{body:c,...r,headers:l([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...o!=null?{"anthropic-workspace-id":o}:void 0},r?.headers])})}list(e={},t){let{betas:r,workspace_id:i,...o}=e??{};return this._client.getAPIList("/v1/agents?beta=true",S,{query:o,...t,headers:l([{"anthropic-beta":[...r??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}archive(e,t={},r){let{betas:i,workspace_id:o}=t??{};return this._client.post(d`/v1/agents/${e}/archive?beta=true`,{...r,headers:l([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...o!=null?{"anthropic-workspace-id":o}:void 0},r?.headers])})}}return n.Versions=lt,n})();function Ae(n,s){if(!n)return()=>{};if(n.aborted)return s.abort(),()=>{};let e=()=>s.abort();return n.addEventListener("abort",e),()=>n.removeEventListener("abort",e)}function Re(n,s){return n instanceof B&&n.status===s}function Pc(n){return n instanceof B&&typeof n.status=="number"&&n.status>=400&&n.status<500}function He(n){return Pc(n)&&!Re(n,408)&&!Re(n,409)&&!Re(n,429)}function Sn(n,s,e){return Math.min(s*2**n,e)}function Vo(n,s){return n+Math.random()*(s-n)}function xn(n){return n*(1-Math.random()*.25)}function vn(n,{authToken:s,helper:e}){if(!s)throw new y(`copyClientForHelper: expected a non-empty authToken but received ${JSON.stringify(s)}`);let t=n,r=t._options.defaultHeaders,i=t._authState?.extraHeaders,o=i?Object.fromEntries(Object.entries(i).filter(([h])=>{let u=h.toLowerCase();return u!=="authorization"&&u!=="x-api-key"})):void 0,c=l([o,r,{[Be]:e}]);return n.withOptions({apiKey:null,authToken:s,baseURL:n.baseURL,credentials:void 0,defaultHeaders:c})}var ut,An,oe,Rn,En,Pn,gr,wr,dt,ht,In,ft,br,Ic=999,Tc=1e3,Mc=6e4,Oc=3e5,yr=(()=>{class n{constructor(e){ut.set(this,void 0),An.set(this,!1),oe.set(this,void 0),Rn.set(this,void 0),En.set(this,void 0),Pn.set(this,void 0),gr.set(this,void 0),wr.set(this,void 0),dt.set(this,void 0),this.client=e.client,this.environmentId=e.environmentId,this.environmentKey=e.environmentKey,this.workerId=e.workerId??Nc(),f(this,ut,vn(e.client,{authToken:e.environmentKey,helper:"environments-work-poller"}),"f"),f(this,En,e.autoStop??!0,"f"),f(this,Pn,e.drain??!1,"f"),f(this,gr,e.blockMs===void 0?Ic:e.blockMs,"f"),f(this,wr,e.reclaimOlderThanMs??null,"f"),f(this,dt,e.requestOptions,"f"),f(this,oe,new AbortController,"f"),f(this,Rn,Ae(e.signal,a(this,oe,"f")),"f")}get signal(){return a(this,oe,"f").signal}abort(){a(this,oe,"f").abort()}async*[(ut=new WeakMap,An=new WeakMap,oe=new WeakMap,Rn=new WeakMap,En=new WeakMap,Pn=new WeakMap,gr=new WeakMap,wr=new WeakMap,dt=new WeakMap,Symbol.asyncIterator)](){if(a(this,An,"f"))throw new y("Cannot iterate over a consumed WorkPoller");f(this,An,!0,"f");let e=T(this.client);e.info("poller starting",{component:"work-poller",environment_id:this.environmentId});let t=new $c(e,this.environmentId);try{let r=0;for(;!a(this,oe,"f").signal.aborted;){let i;try{i=await a(this,ut,"f").beta.environments.work.poll(this.environmentId,{"Anthropic-Worker-ID":this.workerId,...a(this,gr,"f")!==null?{block_ms:a(this,gr,"f")}:{},...a(this,wr,"f")!==null?{reclaim_older_than_ms:a(this,wr,"f")}:{}},{headers:l([a(this,dt,"f")?.headers]),signal:a(this,oe,"f").signal})}catch(o){if(a(this,oe,"f").signal.aborted)return;if(He(o))throw e.error("poll failed permanently, stopping poller",{error:String(o)}),o;let c=xn(Cc(r));e.warn("poll failed, backing off",{error:String(o),backoff_ms:c}),r++,await ue(c,a(this,oe,"f").signal);continue}if(r=0,i==null){if(a(this,Pn,"f"))return;t.onEmptyPoll(),await ue(Vo(1e3,3e3),a(this,oe,"f").signal);continue}t.onClaim(),e.info("claimed work",{component:"work-poller",environment_id:this.environmentId,work_id:i.id,work_type:i.data.type});try{await a(this,ut,"f").beta.environments.work.ack(i.id,{environment_id:i.environment_id},{headers:l([a(this,dt,"f")?.headers]),signal:a(this,oe,"f").signal})}catch(o){e.error("ack failed",{work_id:i.id,error:String(o)});continue}try{yield i}finally{if(a(this,En,"f"))try{await a(this,ut,"f").beta.environments.work.stop(i.id,{environment_id:i.environment_id},{headers:l([a(this,dt,"f")?.headers])})}catch(o){Re(o,409)||e.warn("stop failed",{work_id:i.id,error:String(o)})}}}}finally{a(this,Rn,"f").call(this)}}}return n})();function Cc(n){return Sn(n,Tc,Mc)}var $c=(()=>{class n{constructor(e,t){ht.set(this,void 0),In.set(this,void 0),ft.set(this,void 0),br.set(this,0),f(this,ht,e,"f"),f(this,In,t,"f")}onEmptyPoll(){let e=Date.now(),t={component:"work-poller",environment_id:a(this,In,"f")};a(this,ft,"f")===void 0?(f(this,ft,f(this,br,e,"f"),"f"),a(this,ht,"f").info("idle; polling for work",t)):e-a(this,br,"f")>=Oc?(f(this,br,e,"f"),a(this,ht,"f").info(`still polling; idle for ${Math.round((e-a(this,ft,"f"))/1e3)}s`,t)):a(this,ht,"f").debug("poll returned no work",t)}onClaim(){f(this,ft,void 0,"f")}}return ht=new WeakMap,In=new WeakMap,ft=new WeakMap,br=new WeakMap,n})();function Nc(){let s=globalThis.process?.env?.HOSTNAME;return s?`${s}-${ln()}`:ln()}var pt,Ee,mt,Jo=(()=>{class n{constructor(){pt.set(this,[]),Ee.set(this,[]),mt.set(this,!1)}push(e){if(a(this,mt,"f"))return!1;let t=a(this,Ee,"f").shift();return t?t({done:!1,value:e}):a(this,pt,"f").push(e),!0}close(){if(!a(this,mt,"f"))for(f(this,mt,!0,"f");a(this,Ee,"f").length>0;)a(this,Ee,"f").shift()({done:!0,value:void 0})}next(e){return a(this,pt,"f").length>0?Promise.resolve({done:!1,value:a(this,pt,"f").shift()}):a(this,mt,"f")||e?.aborted?Promise.resolve({done:!0,value:void 0}):new Promise(t=>{let r=o=>{e?.removeEventListener("abort",i),t(o)},i=()=>{let o=a(this,Ee,"f").indexOf(r);o>=0&&a(this,Ee,"f").splice(o,1),t({done:!0,value:void 0})};a(this,Ee,"f").push(r),e?.addEventListener("abort",i,{once:!0})})}tryShift(){return a(this,pt,"f").shift()}}return pt=new WeakMap,Ee=new WeakMap,mt=new WeakMap,n})();function ri(n){return"name"in n?n.name:"mcp_server_name"in n?n.mcp_server_name:n.type}function Lc(n){return n instanceof Ge?n.content:`Error: ${n instanceof Error?n.message:String(n)}`}async function Xo(n,s,e){try{let t=n.parse?n.parse(s):s;return{content:await n.run(t,e),isError:!1}}catch(t){return{content:Lc(t),isError:!0}}}var kr,Tn,_t,De,he,H,Mn,z,On,Sr,Cn,q,gt,te,wt,Pe,bt,Se,$n,xr,ae,Nn,Go,Yo,Qo,Zo,ni,ea,Ln,Fn,si,ta,ra;var na=500,Fc=1e4,Bc=12e4,Hc=3e4,Dc=1e3,Wc=3e4,jc=5*6e4,qc=6e4;function sa(n){return n.type==="session.status_idle"&&n.stop_reason?.type==="end_turn"}var Uc=(()=>{class n{constructor(e,t){kr.set(this,void 0),Tn.set(this,void 0),_t.set(this,new Set),De.set(this,!1),he.set(this,void 0),f(this,kr,e,"f"),f(this,Tn,t,"f")}noteEvent(e){e.type!=="user.tool_confirmation"&&(sa(e)?this.arm():this.disarm())}block(e){a(this,_t,"f").add(e),a(this,he,"f")!==void 0&&(f(this,De,!0,"f"),clearTimeout(a(this,he,"f")),f(this,he,void 0,"f"))}unblock(e){a(this,_t,"f").delete(e),a(this,_t,"f").size===0&&a(this,De,"f")&&this.arm()}arm(){if(!(a(this,kr,"f")<=0)){if(a(this,_t,"f").size>0){f(this,De,!0,"f");return}f(this,De,!1,"f"),a(this,he,"f")!==void 0&&clearTimeout(a(this,he,"f")),f(this,he,setTimeout(a(this,Tn,"f"),a(this,kr,"f")),"f")}}disarm(){f(this,De,!1,"f"),a(this,he,"f")!==void 0&&(clearTimeout(a(this,he,"f")),f(this,he,void 0,"f"))}}return kr=new WeakMap,Tn=new WeakMap,_t=new WeakMap,De=new WeakMap,he=new WeakMap,n})(),vr=(()=>{class n{constructor(e,t){H.add(this),Mn.set(this,!1),z.set(this,void 0),On.set(this,void 0),Sr.set(this,void 0),Cn.set(this,void 0),q.set(this,void 0),gt.set(this,new Set),te.set(this,new Set),wt.set(this,new Map),Pe.set(this,new Map),bt.set(this,new Jo),Se.set(this,0),$n.set(this,jc),xr.set(this,null),ae.set(this,void 0),this.client=t.client,this.sessionId=e,this.tools=t.tools,this.maxIdleMs=t.maxIdleMs??qc,f(this,q,T(t.client),"f"),f(this,Cn,new Map(t.tools.map(r=>[ri(r),r])),"f"),f(this,z,new AbortController,"f"),f(this,On,Ae(t.signal,a(this,z,"f")),"f"),f(this,Sr,t.requestOptions,"f"),f(this,ae,new Uc(this.maxIdleMs,()=>{a(this,q,"f").info("session idle after end_turn; stopping",{component:"session-tool-runner",session_id:this.sessionId,max_idle_ms:this.maxIdleMs}),a(this,z,"f").abort()}),"f")}get signal(){return a(this,z,"f").signal}abort(){a(this,z,"f").abort()}_setSendRetryWindow(e){f(this,$n,e,"f")}async*[(Mn=new WeakMap,z=new WeakMap,On=new WeakMap,Sr=new WeakMap,Cn=new WeakMap,q=new WeakMap,gt=new WeakMap,te=new WeakMap,wt=new WeakMap,Pe=new WeakMap,bt=new WeakMap,Se=new WeakMap,$n=new WeakMap,xr=new WeakMap,ae=new WeakMap,H=new WeakSet,Symbol.asyncIterator)](){if(a(this,Mn,"f"))throw new y("Cannot iterate over a consumed SessionToolRunner");f(this,Mn,!0,"f"),a(this,q,"f").info("session tool runner starting",{component:"session-tool-runner",session_id:this.sessionId});let e=a(this,H,"m",Go).call(this).catch(t=>{a(this,z,"f").signal.aborted||a(this,q,"f").error("stream loop failed",{error:String(t)}),a(this,z,"f").abort()});try{for(;;){let r=await a(this,bt,"f").next(a(this,z,"f").signal);if(r.done)break;yield r.value}await e;let t;for(;(t=a(this,bt,"f").tryShift())!==void 0;)yield t}finally{a(this,z,"f").abort(),a(this,ae,"f").disarm(),await e;try{await a(this,H,"m",ra).call(this)}catch(t){a(this,q,"f").warn("drain failed",{error:String(t)})}a(this,bt,"f").close();for(let t of this.tools)try{await t.close?.()}catch(r){a(this,q,"f").warn("tool.close failed",{tool:ri(t),error:String(r)})}a(this,On,"f").call(this)}}}return Nn=function(){return{...a(this,Sr,"f"),headers:l([_n("session-tool-runner"),a(this,Sr,"f")?.headers]),signal:a(this,z,"f").signal}},Go=async function(){let e=a(this,z,"f"),t=na;for(;!e.signal.aborted;){try{let r=await this.client.beta.sessions.events.stream(this.sessionId,{},a(this,H,"m",Nn).call(this));await a(this,H,"m",Yo).call(this);for await(let i of r)if(t=na,await a(this,H,"m",Zo).call(this,i))return}catch(r){if(e.signal.throwIfAborted(),He(r))throw a(this,q,"f").error("permanent stream failure, shutting down",{error:String(r)}),e.abort(),r;a(this,q,"f").warn("stream disconnected, reconnecting",{error:String(r),backoff_ms:t})}e.signal.throwIfAborted(),await ue(t,e.signal),t=Math.min(t*2,Fc)}},Yo=async function(){let e=a(this,z,"f"),t=[],r=!1;try{for await(let c of this.client.beta.sessions.events.list(this.sessionId,{limit:1e3},a(this,H,"m",Nn).call(this)))a(this,H,"m",Qo).call(this,c,t),r=sa(c)}catch(c){e.signal.throwIfAborted(),a(this,q,"f").warn("reconcile list failed",{error:String(c)});for(let h of t)a(this,gt,"f").delete(h.id);return}let i=t.filter(c=>!a(this,te,"f").has(c.id));a(this,ae,"f").disarm();for(let c of i)await a(this,H,"m",ni).call(this,c);for(let c of[...a(this,Pe,"f").values()]){let h=a(this,wt,"f").get(c.id);h!==void 0&&await a(this,H,"m",Ln).call(this,c,h)}let o=i.filter(c=>!a(this,te,"f").has(c.id)&&!a(this,Pe,"f").has(c.id));r&&o.length===0?a(this,ae,"f").arm():a(this,ae,"f").disarm()},Qo=function(e,t){e.type==="agent.tool_use"||e.type==="agent.custom_tool_use"?(a(this,gt,"f").add(e.id),a(this,te,"f").has(e.id)||t.push(e)):e.type==="user.tool_result"?a(this,te,"f").add(e.tool_use_id):e.type==="user.custom_tool_result"?a(this,te,"f").add(e.custom_tool_use_id):e.type==="user.tool_confirmation"&&(a(this,te,"f").has(e.tool_use_id)||a(this,wt,"f").set(e.tool_use_id,e.result))},Zo=async function(e){switch(a(this,ae,"f").noteEvent(e),e.type){case"agent.tool_use":case"agent.custom_tool_use":return a(this,gt,"f").has(e.id)||(a(this,gt,"f").add(e.id),await a(this,H,"m",ni).call(this,e)),!1;case"user.tool_confirmation":return await a(this,H,"m",ea).call(this,e),!1;case"user.tool_result":return a(this,te,"f").add(e.tool_use_id),!1;case"user.custom_tool_result":return a(this,te,"f").add(e.custom_tool_use_id),!1;case"session.status_terminated":case"session.deleted":return a(this,q,"f").info("session terminated",{component:"session-tool-runner",session_id:this.sessionId}),a(this,z,"f").abort(),!0;default:return!1}},ni=async function(e){let t=e.evaluated_permission,r=t==="deny"?"deny":a(this,wt,"f").get(e.id);if(r===void 0){t===void 0||t==="allow"?await a(this,H,"m",si).call(this,e,void 0):a(this,Pe,"f").has(e.id)||(a(this,q,"f").info("tool call awaiting confirmation; holding",{component:"session-tool-runner",session_id:this.sessionId,tool:e.name,tool_use_id:e.id}),a(this,Pe,"f").set(e.id,e),a(this,ae,"f").block(e.id));return}await a(this,H,"m",Ln).call(this,e,r)},ea=async function(e){a(this,wt,"f").set(e.tool_use_id,e.result);let t=a(this,Pe,"f").get(e.tool_use_id);t!==void 0&&await a(this,H,"m",Ln).call(this,t,e.result)},Ln=async function(e,t){let r=a(this,Pe,"f").delete(e.id);if(t==="allow"){a(this,q,"f").info("tool call confirmed",{component:"session-tool-runner",session_id:this.sessionId,tool:e.name,tool_use_id:e.id}),r||a(this,ae,"f").block(e.id);try{await a(this,H,"m",si).call(this,e,"allow")}finally{a(this,ae,"f").unblock(e.id)}return}r&&a(this,ae,"f").unblock(e.id),a(this,te,"f").add(e.id),a(this,q,"f").info("tool call denied; not executing",{component:"session-tool-runner",session_id:this.sessionId,tool:e.name,tool_use_id:e.id}),a(this,H,"m",Fn).call(this,{event:e,toolUseId:e.id,name:e.name,isError:!1,posted:!1,confirmation:"deny"})},Fn=function(e){a(this,bt,"f").push(e)},si=async function(e,t){var r,i;if(!a(this,te,"f").has(e.id)){a(this,q,"f").info("executing tool",{component:"session-tool-runner",session_id:this.sessionId,tool:e.name,tool_use_id:e.id}),f(this,Se,(r=a(this,Se,"f"),r++,r),"f");try{let o=a(this,Cn,"f").get(e.name);if(!o){a(this,q,"f").info("tool not owned by this runner; leaving the tool_use_id pending for its owner",{component:"session-tool-runner",session_id:this.sessionId,tool:e.name,tool_use_id:e.id}),a(this,H,"m",Fn).call(this,{event:e,toolUseId:e.id,name:e.name,isError:!1,posted:!1,confirmation:t});return}let c,h,u=new AbortController,g=Ae(a(this,z,"f").signal,u),p=setTimeout(()=>u.abort(),Bc);try{let _=await Xo(o,e.input,{toolUse:e,toolUseBlock:e,signal:u.signal});c=_.content,h=_.isError}finally{clearTimeout(p),g()}let m=zc(e,h,Kc(c)),b=await a(this,H,"m",ta).call(this,m,e.id);a(this,H,"m",Fn).call(this,{event:e,result:m,toolUseId:e.id,name:e.name,isError:h,posted:b,confirmation:t})}finally{f(this,Se,(i=a(this,Se,"f"),i--,i),"f"),a(this,Se,"f")===0&&a(this,xr,"f")?.call(this)}}},ta=async function(e,t){let r=a(this,z,"f"),i=Date.now(),o,c=0;for(;;){c++,r.signal.throwIfAborted();try{return await this.client.beta.sessions.events.send(this.sessionId,{events:[e]},a(this,H,"m",Nn).call(this)),a(this,te,"f").add(t),!0}catch(h){if(o=h,He(h))break;let u=a(this,$n,"f")-(Date.now()-i);if(u<=0)break;let g=Math.min(xn(Sn(c-1,Dc,Wc)),u);a(this,q,"f").warn("tool result send failed; retrying",{tool_use_id:t,attempt:c,backoff_ms:g,error:String(h)}),await ue(g,r.signal)}}return a(this,q,"f").error("failed to send tool result",{tool_use_id:t,attempts:c,error:String(o)}),!1},ra=async function(){a(this,Se,"f")!==0&&(await Promise.race([new Promise(e=>f(this,xr,e,"f")),ue(Hc)]),f(this,xr,null,"f"),a(this,Se,"f")>0&&a(this,q,"f").warn("drain timeout exceeded"))},n})();function zc(n,s,e){return n.type==="agent.custom_tool_use"?{type:"user.custom_tool_result",custom_tool_use_id:n.id,is_error:s,content:e}:{type:"user.tool_result",tool_use_id:n.id,is_error:s,content:e}}function Kc(n){if(typeof n=="string")return[{type:"text",text:n||"(no output)"}];let s=n.map(e=>e.type==="text"?{type:"text",text:e.text||"(no output)"}:e.type==="image"||e.type==="document"?e:e.type==="search_result"?{type:"search_result",source:e.source,title:e.title,content:e.content.map(t=>({type:"text",text:t.text})),citations:{enabled:e.citations?.enabled??!1}}:{type:"text",text:JSON.stringify(e)});return s.length>0?s:[{type:"text",text:"(no output)"}]}var Bn,Ar,ii,Rr,yt,ia=3e4,Vc=9e4,Jc="NO_HEARTBEAT";function Xc(n){return n.resources.some(s=>s.type==="memory_store")}function Gc(n){if(!n)return null;let s;try{let t=n.replace(/-/g,"+").replace(/_/g,"/"),r=t.padEnd(Math.ceil(t.length/4)*4,"=");s=JSON.parse(cr(po(r)))}catch{return null}if(s===null||typeof s!="object"||Array.isArray(s))return null;let e=s.sessions_token;return typeof e=="string"&&e!==""?e:null}var oi=(()=>{class n{constructor(e){if(Bn.add(this),Ar.set(this,void 0),e.unrestrictedPaths!==void 0)throw new y("The `unrestrictedPaths` option you passed to EnvironmentWorker (or client.beta.environments.work.worker()) is no longer supported. The worker's file tools (read, write, edit, glob, grep) are now always confined to `workdir` plus the session's memory folders. Remove `unrestrictedPaths` from your options; to let the file tools reach any other directory, add it to `AgentToolContext.allowedRoots` from a `tools` factory.");this.client=e.client,this.environmentId=e.environmentId,this.environmentKey=e.environmentKey,this.tools=e.tools,this.workdir=e.workdir??process.cwd(),this.maxFileBytes=e.maxFileBytes,this.maxIdleMs=e.maxIdleMs,e.memorySyncIntervalMs!=null&&Li(e.memorySyncIntervalMs,"memorySyncIntervalMs"),this.memorySyncIntervalMs=e.memorySyncIntervalMs,this.memorySyncDeletions=e.memorySyncDeletions??"enabled",this.workerId=e.workerId,this.requestOptions=e.requestOptions,f(this,Ar,e.signal,"f")}async run(e){let{environmentId:t,environmentKey:r}=this;if(t===void 0||r===void 0)throw new y("EnvironmentWorker.run: environmentId and environmentKey are required to poll for work");let i=e??a(this,Ar,"f"),o=new yr({client:this.client,environmentId:t,environmentKey:r,...this.workerId!==void 0?{workerId:this.workerId}:{},...i?{signal:i}:{},...this.requestOptions!==void 0?{requestOptions:this.requestOptions}:{},autoStop:!1});for await(let c of o)try{await a(this,Bn,"m",ii).call(this,c,r,o.signal)}catch(h){if(o.signal?.aborted)throw h;T(this.client).error("work item failed",{work_id:c.id,error:String(h)})}}async handleItem(e){let t=e?.workId??P("ANTHROPIC_WORK_ID"),r=e?.environmentId??P("ANTHROPIC_ENVIRONMENT_ID"),i=e?.sessionId??P("ANTHROPIC_SESSION_ID"),o=(e?.environmentKey??this.environmentKey??P("ANTHROPIC_ENVIRONMENT_KEY"))||void 0,c=e?.workSecret||P("ANTHROPIC_WORK_SECRET")||null;if(!t)throw new y("handleItem: workId is required \u2014 pass it or set ANTHROPIC_WORK_ID");if(!r)throw new y("handleItem: environmentId is required \u2014 pass it or set ANTHROPIC_ENVIRONMENT_ID");if(!i)throw new y("handleItem: sessionId is required \u2014 pass it or set ANTHROPIC_SESSION_ID");if(!o&&!c)throw new y("handleItem: environmentKey is required when there is no work secret \u2014 pass it, construct the worker with it, or set ANTHROPIC_ENVIRONMENT_KEY");let h={id:t,environment_id:r,secret:c,data:{type:"session",id:i}};await a(this,Bn,"m",ii).call(this,h,o,e?.signal??a(this,Ar,"f"))}}return Ar=new WeakMap,Bn=new WeakSet,ii=async function(e,t,r){let i=T(this.client),o=Gc(e.secret),c=o??t;if(c===void 0)throw new y("handleItem: the work item carried a secret payload but no sessions token could be extracted, and there is no environment key to fall back to; the poller must issue a secret whose payload carries `sessions_token`, or provide the environment key (pass it, construct the worker with it, or set ANTHROPIC_ENVIRONMENT_KEY)");e.secret&&o===null&&i.warn("work item carried a secret payload but no sessions token could be extracted; falling back to the environment key",{work_id:e.id});let h=vn(this.client,{authToken:c,helper:"environments-worker"}),u=e.data.id,g=new AbortController,p=Ae(r,g),m=new Qc(g),b=await import("./node-DAO3SX7O.js"),_,x,A=el(h,e,m,i,this.requestOptions,v=>{_=v,x?._setSendRetryWindow(v)}).catch(v=>{g.signal.aborted||i.error("heartbeat loop failed",{work_id:e.id,error:String(v)}),g.abort()}),E=async()=>{},k,I=!1;try{if(e.data.type!=="session"){i.debug("skipping non-session work item",{work_id:e.id,type:e.data.type});return}let v=await h.beta.sessions.retrieve(u);if(o===null&&this.memorySyncIntervalMs!==null&&Xc(v))throw new b.SessionMemoryError(`cannot mount the session's memories: the work item carried no sessions token (work_id=${e.id}, session_id=${u}); the memory endpoints reject the environment key, so the poller must issue a per-item \`secret\` carrying \`sessions_token\`, or set \`memorySyncIntervalMs: null\` to run without memory`);let R={workdir:this.workdir,client:h,session:v,...this.maxFileBytes!==void 0?{maxFileBytes:this.maxFileBytes}:{}};try{E=await b.setupSkills(R)}catch(M){i.warn("skill setup failed",{session_id:u,work_id:e.id,error:String(M)})}o!==null&&this.memorySyncIntervalMs!==null?(k=new b.SessionMemoryStores(h,{workdir:this.workdir,...this.memorySyncIntervalMs!==void 0?{syncIntervalMs:this.memorySyncIntervalMs}:{},syncDeletions:this.memorySyncDeletions}),await k.download(v),R.allowedRoots=k.roots,R.readOnlyRoots=k.readOnlyRoots):i.debug("memory stores disabled for this item",{work_id:e.id});let C=typeof this.tools=="function"?this.tools(R):this.tools??b.betaAgentToolset20260401(R);x=new vr(u,{client:h,tools:C,...this.maxIdleMs!==void 0?{maxIdleMs:this.maxIdleMs}:{},...this.requestOptions!==void 0?{requestOptions:this.requestOptions}:{},signal:g.signal}),_!==void 0&&x._setSendRetryWindow(_);for await(let M of x)k&&await k.syncIfDue();I=!g.signal.aborted}finally{try{await E().catch(v=>{i.warn("skill cleanup failed",{session_id:u,work_id:e.id,error:String(v)})})}finally{if(k){let v=b.MEMORY_FLUSH_TIMEOUT_MS;I&&await oa(k.finish(),v)&&i.warn(`final memory sync cut off after ${v}ms; the flush that follows still uploads changed files`,{session_id:u,work_id:e.id});let R=new AbortController;await oa(k.flushWrites(R.signal),v)&&(R.abort(),i.warn(`memory flush cut off after ${v}ms; changed files it had not uploaded yet are not saved`,{session_id:u,work_id:e.id})),await k.dispose().catch(M=>{i.warn("memory store cleanup failed",{session_id:u,work_id:e.id,error:String(M)})})}}m.finish("runner_done"),p(),await A,m.lost?i.info("lease lost; released without stopping it",{session_id:u,work_id:e.id}):await Yc(h,e,i,this.requestOptions)}},n})();async function oa(n,s){let e;try{return await Promise.race([n.then(()=>!1,()=>!1),new Promise(t=>{e=setTimeout(()=>t(!0),s)})])}finally{e!==void 0&&clearTimeout(e)}}async function Yc(n,s,e,t){try{await n.beta.environments.work.stop(s.id,{environment_id:s.environment_id,force:!0},{...t,headers:l([t?.headers])})}catch(r){Re(r,409)||e.error("force-stop on exit failed",{work_id:s.id,error:String(r)})}}var Qc=(()=>{class n{constructor(e){Rr.set(this,void 0),yt.set(this,void 0),f(this,Rr,e,"f")}get signal(){return a(this,Rr,"f").signal}finish(e){f(this,yt,a(this,yt,"f")??e,"f"),a(this,Rr,"f").abort()}get lost(){return a(this,yt,"f")==="lease_lost"||a(this,yt,"f")==="assumed_lost"}}return Rr=new WeakMap,yt=new WeakMap,n})();function Zc(n){let s=n instanceof B?n.error:void 0;for(let e of["error","details","current_state"]){if(!Is(s))return{};s=s[e]}return Is(s)?s:{}}async function el(n,s,e,t,r,i){let o=ia,c=Vc,h=Date.now(),u=Jc,g=async()=>{let p=new AbortController,m=Ae(e.signal,p),b=setTimeout(()=>p.abort(),o);try{let _=await n.beta.environments.work.heartbeat(s.id,{environment_id:s.environment_id,expected_last_heartbeat:u},{...r,headers:l([r?.headers]),signal:p.signal});h=Date.now(),u=_.last_heartbeat,_.ttl_seconds>0&&(c=_.ttl_seconds*1e3,o=Math.max(1e3,Math.min(c/2,ia)),i?.(c)),(_.state==="stopping"||_.state==="stopped")&&(t.info("heartbeat signals shutdown",{work_id:s.id,state:_.state}),e.finish("control_plane_stop")),_.lease_extended||(t.warn("lease not extended, shutting down",{work_id:s.id}),e.finish("control_plane_stop"))}catch(_){if(e.signal.throwIfAborted(),Re(_,412)){let x=Zc(_);t.error("lease lost: heartbeat precondition failed",{work_id:s.id,server_state:x.state,server_ttl_seconds:x.ttl_seconds,server_last_heartbeat:x.last_heartbeat}),e.finish("lease_lost");return}if(He(_))throw t.error("permanent heartbeat failure",{work_id:s.id,error:String(_)}),e.finish("heartbeat_rejected"),_;if(Date.now()-h>c){t.error("lease assumed lost: no successful heartbeat in ttl",{work_id:s.id,ttl_ms:c,error:String(_)}),e.finish("assumed_lost");return}t.warn("transient heartbeat failure",{work_id:s.id,error:String(_)})}finally{clearTimeout(b),m()}};for(await g();!e.signal.aborted;)await ue(o,e.signal),e.signal.throwIfAborted(),await g()}var Hn=(()=>{class n extends w{retrieve(e,t,r){let{environment_id:i,betas:o,workspace_id:c}=t;return this._client.get(d`/v1/environments/${i}/work/${e}?beta=true`,{...r,headers:l([{"anthropic-beta":[...o??[],"managed-agents-2026-04-01"].toString(),...c!=null?{"anthropic-workspace-id":c}:void 0},r?.headers])})}update(e,t,r){let{environment_id:i,betas:o,workspace_id:c,...h}=t;return this._client.post(d`/v1/environments/${i}/work/${e}?beta=true`,{body:h,...r,headers:l([{"anthropic-beta":[...o??[],"managed-agents-2026-04-01"].toString(),...c!=null?{"anthropic-workspace-id":c}:void 0},r?.headers])})}list(e,t={},r){let{betas:i,...o}=t??{};return this._client.getAPIList(d`/v1/environments/${e}/work?beta=true`,S,{query:o,...r,headers:l([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString()},r?.headers])})}ack(e,t,r){let{environment_id:i,betas:o}=t;return this._client.post(d`/v1/environments/${i}/work/${e}/ack?beta=true`,{...r,headers:l([{"anthropic-beta":[...o??[],"managed-agents-2026-04-01"].toString()},r?.headers])})}heartbeat(e,t,r){let{environment_id:i,desired_ttl_seconds:o,expected_last_heartbeat:c,betas:h}=t;return this._client.post(d`/v1/environments/${i}/work/${e}/heartbeat?beta=true`,{query:{desired_ttl_seconds:o,expected_last_heartbeat:c},...r,headers:l([{"anthropic-beta":[...h??[],"managed-agents-2026-04-01"].toString()},r?.headers])})}poll(e,t={},r){let{betas:i,"Anthropic-Worker-ID":o,...c}=t??{};return this._client.get(d`/v1/environments/${e}/work/poll?beta=true`,{query:c,...r,headers:l([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...o!=null?{"Anthropic-Worker-ID":o}:void 0},r?.headers])})}stats(e,t={},r){let{betas:i,workspace_id:o}=t??{};return this._client.get(d`/v1/environments/${e}/work/stats?beta=true`,{...r,headers:l([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...o!=null?{"anthropic-workspace-id":o}:void 0},r?.headers])})}stop(e,t,r){let{environment_id:i,betas:o,workspace_id:c,...h}=t;return this._client.post(d`/v1/environments/${i}/work/${e}/stop?beta=true`,{body:h,...r,headers:l([{"anthropic-beta":[...o??[],"managed-agents-2026-04-01"].toString(),...c!=null?{"anthropic-workspace-id":c}:void 0},r?.headers])})}poller(e){return new yr({...e,client:this._client})}worker(e){return new oi({...e,client:this._client})}}return n.WorkPoller=yr,n.EnvironmentWorker=oi,n})();var Dn=(()=>{class n extends w{constructor(){super(...arguments),this.work=new Hn(this._client)}create(e,t){let{betas:r,workspace_id:i,...o}=e;return this._client.post("/v1/environments?beta=true",{body:o,...t,headers:l([{"anthropic-beta":[...r??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}retrieve(e,t={},r){let{betas:i,workspace_id:o}=t??{};return this._client.get(d`/v1/environments/${e}?beta=true`,{...r,headers:l([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...o!=null?{"anthropic-workspace-id":o}:void 0},r?.headers])})}update(e,t,r){let{betas:i,workspace_id:o,...c}=t;return this._client.post(d`/v1/environments/${e}?beta=true`,{body:c,...r,headers:l([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...o!=null?{"anthropic-workspace-id":o}:void 0},r?.headers])})}list(e={},t){let{betas:r,workspace_id:i,...o}=e??{};return this._client.getAPIList("/v1/environments?beta=true",S,{query:o,...t,headers:l([{"anthropic-beta":[...r??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}delete(e,t={},r){let{betas:i,workspace_id:o}=t??{};return this._client.delete(d`/v1/environments/${e}?beta=true`,{...r,headers:l([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...o!=null?{"anthropic-workspace-id":o}:void 0},r?.headers])})}archive(e,t={},r){let{betas:i,workspace_id:o}=t??{};return this._client.post(d`/v1/environments/${e}/archive?beta=true`,{...r,headers:l([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...o!=null?{"anthropic-workspace-id":o}:void 0},r?.headers])})}}return n.Work=Hn,n})();var kt=class extends w{create(s,e,t){let{view:r,betas:i,workspace_id:o,...c}=e;return this._client.post(d`/v1/memory_stores/${s}/memories?beta=true`,{query:{view:r},body:c,...t,headers:l([{"anthropic-beta":[...i??[],"agent-memory-2026-07-22"].toString(),...o!=null?{"anthropic-workspace-id":o}:void 0},t?.headers])})}retrieve(s,e,t){let{memory_store_id:r,betas:i,workspace_id:o,...c}=e;return this._client.get(d`/v1/memory_stores/${r}/memories/${s}?beta=true`,{query:c,...t,headers:l([{"anthropic-beta":[...i??[],"agent-memory-2026-07-22"].toString(),...o!=null?{"anthropic-workspace-id":o}:void 0},t?.headers])})}update(s,e,t){let{memory_store_id:r,view:i,betas:o,workspace_id:c,...h}=e;return this._client.post(d`/v1/memory_stores/${r}/memories/${s}?beta=true`,{query:{view:i},body:h,...t,headers:l([{"anthropic-beta":[...o??[],"agent-memory-2026-07-22"].toString(),...c!=null?{"anthropic-workspace-id":c}:void 0},t?.headers])})}list(s,e={},t){let{betas:r,workspace_id:i,...o}=e??{};return this._client.getAPIList(d`/v1/memory_stores/${s}/memories?beta=true`,S,{query:o,...t,headers:l([{"anthropic-beta":[...r??[],"agent-memory-2026-07-22"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}delete(s,e,t){let{memory_store_id:r,expected_content_sha256:i,betas:o,workspace_id:c}=e;return this._client.delete(d`/v1/memory_stores/${r}/memories/${s}?beta=true`,{query:{expected_content_sha256:i},...t,headers:l([{"anthropic-beta":[...o??[],"agent-memory-2026-07-22"].toString(),...c!=null?{"anthropic-workspace-id":c}:void 0},t?.headers])})}};var St=class extends w{retrieve(s,e,t){let{memory_store_id:r,betas:i,workspace_id:o,...c}=e;return this._client.get(d`/v1/memory_stores/${r}/memory_versions/${s}?beta=true`,{query:c,...t,headers:l([{"anthropic-beta":[...i??[],"agent-memory-2026-07-22"].toString(),...o!=null?{"anthropic-workspace-id":o}:void 0},t?.headers])})}list(s,e={},t){let{betas:r,workspace_id:i,...o}=e??{};return this._client.getAPIList(d`/v1/memory_stores/${s}/memory_versions?beta=true`,S,{query:o,...t,headers:l([{"anthropic-beta":[...r??[],"agent-memory-2026-07-22"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}redact(s,e,t){let{memory_store_id:r,betas:i,workspace_id:o}=e;return this._client.post(d`/v1/memory_stores/${r}/memory_versions/${s}/redact?beta=true`,{...t,headers:l([{"anthropic-beta":[...i??[],"agent-memory-2026-07-22"].toString(),...o!=null?{"anthropic-workspace-id":o}:void 0},t?.headers])})}};var Wn=(()=>{class n extends w{constructor(){super(...arguments),this.memories=new kt(this._client),this.memoryVersions=new St(this._client)}create(e,t){let{betas:r,workspace_id:i,...o}=e;return this._client.post("/v1/memory_stores?beta=true",{body:o,...t,headers:l([{"anthropic-beta":[...r??[],"agent-memory-2026-07-22"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}retrieve(e,t={},r){let{betas:i,workspace_id:o}=t??{};return this._client.get(d`/v1/memory_stores/${e}?beta=true`,{...r,headers:l([{"anthropic-beta":[...i??[],"agent-memory-2026-07-22"].toString(),...o!=null?{"anthropic-workspace-id":o}:void 0},r?.headers])})}update(e,t,r){let{betas:i,workspace_id:o,...c}=t;return this._client.post(d`/v1/memory_stores/${e}?beta=true`,{body:c,...r,headers:l([{"anthropic-beta":[...i??[],"agent-memory-2026-07-22"].toString(),...o!=null?{"anthropic-workspace-id":o}:void 0},r?.headers])})}list(e={},t){let{betas:r,workspace_id:i,...o}=e??{};return this._client.getAPIList("/v1/memory_stores?beta=true",S,{query:o,...t,headers:l([{"anthropic-beta":[...r??[],"agent-memory-2026-07-22"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}delete(e,t={},r){let{betas:i,workspace_id:o}=t??{};return this._client.delete(d`/v1/memory_stores/${e}?beta=true`,{...r,headers:l([{"anthropic-beta":[...i??[],"agent-memory-2026-07-22"].toString(),...o!=null?{"anthropic-workspace-id":o}:void 0},r?.headers])})}archive(e,t={},r){let{betas:i,workspace_id:o}=t??{};return this._client.post(d`/v1/memory_stores/${e}/archive?beta=true`,{...r,headers:l([{"anthropic-beta":[...i??[],"agent-memory-2026-07-22"].toString(),...o!=null?{"anthropic-workspace-id":o}:void 0},r?.headers])})}}return n.Memories=kt,n.MemoryVersions=St,n})();var jn=(()=>{class n{constructor(e,t){this.iterator=e,this.controller=t}async*decoder(){let e=new ur;for await(let t of this.iterator)for(let r of e.decode(t))yield JSON.parse(r);for(let t of e.flush())yield JSON.parse(t)}[Symbol.asyncIterator](){return this.decoder()}static fromResponse(e,t){if(!e.body)throw t.abort(),typeof globalThis.navigator<"u"&&globalThis.navigator.product==="ReactNative"?new y("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 y("Attempted to iterate over a response with no body");return new n(ar(e.body),t)}}return n})();var xt=class extends w{create(s,e){let{betas:t,user_profile_id:r,workspace_id:i,...o}=s;return this._client.post("/v1/messages/batches?beta=true",{body:o,...e,headers:l([{"anthropic-beta":[...t??[],"message-batches-2024-09-24"].toString(),...r!=null?{"anthropic-user-profile-id":r}:void 0,...i!=null?{"anthropic-workspace-id":i}:void 0},e?.headers])})}retrieve(s,e={},t){let{betas:r,workspace_id:i}=e??{};return this._client.get(d`/v1/messages/batches/${s}?beta=true`,{...t,headers:l([{"anthropic-beta":[...r??[],"message-batches-2024-09-24"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}list(s={},e){let{betas:t,workspace_id:r,...i}=s??{};return this._client.getAPIList("/v1/messages/batches?beta=true",W,{query:i,...e,headers:l([{"anthropic-beta":[...t??[],"message-batches-2024-09-24"].toString(),...r!=null?{"anthropic-workspace-id":r}:void 0},e?.headers])})}delete(s,e={},t){let{betas:r,workspace_id:i}=e??{};return this._client.delete(d`/v1/messages/batches/${s}?beta=true`,{...t,headers:l([{"anthropic-beta":[...r??[],"message-batches-2024-09-24"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}cancel(s,e={},t){let{betas:r,workspace_id:i}=e??{};return this._client.post(d`/v1/messages/batches/${s}/cancel?beta=true`,{...t,headers:l([{"anthropic-beta":[...r??[],"message-batches-2024-09-24"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}async results(s,e={},t){let r=await this.retrieve(s,e,t);if(!r.results_url)throw new y(`No batch \`results_url\`; Has it finished processing? ${r.processing_status} - ${r.id}`);let{betas:i,workspace_id:o}=e??{};return this._client.get(r.results_url,{...t,headers:l([{"anthropic-beta":[...i??[],"message-batches-2024-09-24"].toString(),Accept:"application/binary",...o!=null?{"anthropic-workspace-id":o}:void 0},t?.headers]),stream:!0,__binaryResponse:!0})._thenUnwrap((c,h)=>jn.fromResponse(h.response,h.controller))}};var qn={"claude-opus-4@20250514":8192,"anthropic.claude-opus-4-1-20250805-v1:0":8192,"claude-opus-4-1@20250805":8192};function aa(n){return n?.output_format??n?.output_config?.format}function ai(n,s,e){let t=aa(s);return!s||!("parse"in(t??{}))?{...n,content:n.content.map(r=>{if(r.type==="text"){let i=Object.defineProperty({...r},"parsed_output",{value:null,enumerable:!1});return Object.defineProperty(i,"parsed",{get(){return e.logger.warn("The `parsed` property on `text` blocks is deprecated, please use `parsed_output` instead."),null},enumerable:!1})}return r}),parsed_output:null}:ci(n,s,e)}function ci(n,s,e){let t=null,r=n.content.map(i=>{if(i.type==="text"){let o=al(s,i.text);t===null&&(t=o);let c=Object.defineProperty({...i},"parsed_output",{value:o,enumerable:!1});return Object.defineProperty(c,"parsed",{get(){return e.logger.warn("The `parsed` property on `text` blocks is deprecated, please use `parsed_output` instead."),o},enumerable:!1})}return i});return{...n,content:r,parsed_output:t}}function al(n,s){let e=aa(n);if(e?.type!=="json_schema")return null;try{return"parse"in e?e.parse(s):JSON.parse(s)}catch(t){throw new y(`Failed to parse structured output: ${t}`)}}var cl=n=>{let s=0,e=[];for(;s<n.length;){let t=n[s];if(t==="\\"){s++;continue}if(t==="{"){e.push({type:"brace",value:"{"}),s++;continue}if(t==="}"){e.push({type:"brace",value:"}"}),s++;continue}if(t==="["){e.push({type:"paren",value:"["}),s++;continue}if(t==="]"){e.push({type:"paren",value:"]"}),s++;continue}if(t===":"){e.push({type:"separator",value:":"}),s++;continue}if(t===","){e.push({type:"delimiter",value:","}),s++;continue}if(t==='"'){let c=s+1,h=c,u=!1;for(;;){if(h=n.indexOf('"',h),h===-1){u=!0;break}let g=0,p=h-1;for(;p>=c&&n[p]==="\\";)g++,p--;if(g%2===0)break;h++}u?s=n.length:(e.push({type:"string",value:n.slice(c,h)}),s=h+1);continue}if(t&&/\s/.test(t)){s++;continue}let i=/[0-9]/;if(t&&i.test(t)||t==="-"||t==="."){let c="";for(t==="-"&&(c+=t,t=n[++s]);t&&(i.test(t)||t==="."||t==="e"||t==="E"||(t==="-"||t==="+")&&(c[c.length-1]==="e"||c[c.length-1]==="E"));)c+=t,t=n[++s];e.push({type:"number",value:c,unterminated:s===n.length});continue}let o=/[a-z]/i;if(t&&o.test(t)){let c="";for(;t&&o.test(t)&&s!==n.length;)c+=t,t=n[++s];if(c=="true"||c=="false"||c==="null")e.push({type:"name",value:c});else{s++;continue}continue}s++}return e},ll=n=>{let s=[];for(let i of n)(i.type==="brace"||i.type==="paren")&&(i.value==="{"||i.value==="["?s.push(i.value):s.pop());let e=s[s.length-1],t=n.length,r=/^-?(0|[1-9][0-9]*)(\.[0-9]+)?([eE][-+]?[0-9]+)?$/;for(;t>0;){let i=n[t-1];switch(i.type){case"separator":t--;continue;case"number":if(i.unterminated||!r.test(i.value)){t--;continue}break;case"string":let o=n[t-2];if(e==="{"&&(o?.type==="delimiter"||o?.type==="brace"&&o.value==="{")){t--;continue}break;case"delimiter":t--;break}break}return n.slice(0,t)},ul=n=>{let s=[];return n.map(e=>{e.type==="brace"&&(e.value==="{"?s.push("}"):s.splice(s.lastIndexOf("}"),1)),e.type==="paren"&&(e.value==="["?s.push("]"):s.splice(s.lastIndexOf("]"),1))}),s.length>0&&s.reverse().map(e=>{e==="}"?n.push({type:"brace",value:"}"}):e==="]"&&n.push({type:"paren",value:"]"})}),n},dl=n=>{let s="";return n.map(e=>{e.type==="string"?s+='"'+e.value+'"':s+=e.value}),s},ca=n=>JSON.parse(dl(ul(ll(cl(n)))));var Ie="__json_buf";function Un(n,s){let e={};for(let i of Object.keys(n))i!=="input"&&(e[i]=n[i]);Object.defineProperty(e,Ie,{value:s,enumerable:!1,writable:!0});let t,r=!1;return Object.defineProperty(e,"input",{enumerable:!0,configurable:!0,get(){return r||(t=s?ca(s):{},r=!0),t}}),e}var X,Te,vt,Er,zn,Pr,Ir,Kn,Tr,ge,Mr,Vn,Jn,We,Xn,Gn,Yn,Or,li,la,Cr,ui,di,hi,ua,fi;function pi(n){return n.type==="tool_use"||n.type==="server_tool_use"||n.type==="mcp_tool_use"}var Qn=(()=>{class n{constructor(e,t){X.add(this),this.messages=[],this.receivedMessages=[],Te.set(this,void 0),vt.set(this,null),this.controller=new AbortController,Er.set(this,void 0),zn.set(this,()=>{}),Pr.set(this,()=>{}),Ir.set(this,void 0),Kn.set(this,()=>{}),Tr.set(this,()=>{}),ge.set(this,{}),Mr.set(this,!1),Vn.set(this,!1),Jn.set(this,!1),We.set(this,!1),Xn.set(this,void 0),Gn.set(this,void 0),Yn.set(this,void 0),Or.set(this,void 0),Cr.set(this,r=>{if(f(this,Vn,!0,"f"),le(r)&&(r=new K),r instanceof K)return f(this,Jn,!0,"f"),this._emit("abort",r);if(r instanceof y)return this._emit("error",r);if(r instanceof Error){let i=new y(r.message);return i.cause=r,this._emit("error",i)}return this._emit("error",new y(String(r)))}),f(this,Er,new Promise((r,i)=>{f(this,zn,r,"f"),f(this,Pr,i,"f")}),"f"),f(this,Ir,new Promise((r,i)=>{f(this,Kn,r,"f"),f(this,Tr,i,"f")}),"f"),a(this,Er,"f").catch(()=>{}),a(this,Ir,"f").catch(()=>{}),f(this,vt,e,"f"),f(this,Or,t?.logger??console,"f")}get response(){return a(this,Xn,"f")}get request_id(){return a(this,Gn,"f")}get workspace_id(){return a(this,Yn,"f")}async withResponse(){f(this,We,!0,"f");let e=await a(this,Er,"f");if(!e)throw new Error("Could not resolve a `Response` object");return{data:this,response:e,request_id:e.headers.get("request-id"),workspace_id:e.headers.get("anthropic-workspace-id")}}static fromReadableStream(e){let t=new n(null);return t._run(()=>t._fromReadableStream(e)),t}static createMessage(e,t,r,{logger:i}={}){let o=new n(t,{logger:i});for(let c of t.messages)o._addMessageParam(c);return f(o,vt,{...t,stream:!0},"f"),o._run(()=>o._createMessage(e,{...t,stream:!0},{...r,headers:{...r?.headers,[nt]:"stream"}})),o}_run(e){e().then(()=>{this._emitFinal(),this._emit("end")},a(this,Cr,"f"))}_addMessageParam(e){this.messages.push(e)}_addMessage(e,t=!0){this.receivedMessages.push(e),t&&this._emit("message",e)}async _createMessage(e,t,r){let i=r?.signal,o;i&&(i.aborted&&this.controller.abort(),o=this.controller.abort.bind(this.controller),i.addEventListener("abort",o));try{a(this,X,"m",ui).call(this);let{response:c,data:h}=await e.create({...t,stream:!0},{...r,signal:this.controller.signal}).withResponse();this._connected(c);for await(let u of h)a(this,X,"m",di).call(this,u);if(h.controller.signal?.aborted)throw new K;a(this,X,"m",hi).call(this)}finally{i&&o&&i.removeEventListener("abort",o)}}_connected(e){this.ended||(f(this,Xn,e,"f"),f(this,Gn,e?.headers.get("request-id"),"f"),f(this,Yn,e?.headers.get("anthropic-workspace-id"),"f"),a(this,zn,"f").call(this,e),this._emit("connect"))}get ended(){return a(this,Mr,"f")}get errored(){return a(this,Vn,"f")}get aborted(){return a(this,Jn,"f")}abort(){this.controller.abort()}on(e,t){return(a(this,ge,"f")[e]||(a(this,ge,"f")[e]=[])).push({listener:t}),this}off(e,t){let r=a(this,ge,"f")[e];if(!r)return this;let i=r.findIndex(o=>o.listener===t);return i>=0&&r.splice(i,1),this}once(e,t){return(a(this,ge,"f")[e]||(a(this,ge,"f")[e]=[])).push({listener:t,once:!0}),this}emitted(e){return new Promise((t,r)=>{f(this,We,!0,"f"),e!=="error"&&this.once("error",r),this.once(e,t)})}async done(){f(this,We,!0,"f"),await a(this,Ir,"f")}get currentMessage(){return a(this,Te,"f")}async finalMessage(){return await this.done(),a(this,X,"m",li).call(this)}async finalText(){return await this.done(),a(this,X,"m",la).call(this)}_emit(e,...t){if(a(this,Mr,"f"))return;e==="end"&&(f(this,Mr,!0,"f"),a(this,Kn,"f").call(this));let r=a(this,ge,"f")[e];if(r&&(a(this,ge,"f")[e]=r.filter(i=>!i.once),r.forEach(({listener:i})=>i(...t))),e==="abort"){let i=t[0];!a(this,We,"f")&&!r?.length&&Promise.reject(i),a(this,Pr,"f").call(this,i),a(this,Tr,"f").call(this,i),this._emit("end");return}if(e==="error"){let i=t[0];!a(this,We,"f")&&!r?.length&&Promise.reject(i),a(this,Pr,"f").call(this,i),a(this,Tr,"f").call(this,i),this._emit("end")}}_emitFinal(){this.receivedMessages.at(-1)&&this._emit("finalMessage",a(this,X,"m",li).call(this))}async _fromReadableStream(e,t){let r=t?.signal,i;r&&(r.aborted&&this.controller.abort(),i=this.controller.abort.bind(this.controller),r.addEventListener("abort",i));try{a(this,X,"m",ui).call(this),this._connected(null);let o=_e.fromReadableStream(e,this.controller);for await(let c of o)a(this,X,"m",di).call(this,c);if(o.controller.signal?.aborted)throw new K;a(this,X,"m",hi).call(this)}finally{r&&i&&r.removeEventListener("abort",i)}}[(Te=new WeakMap,vt=new WeakMap,Er=new WeakMap,zn=new WeakMap,Pr=new WeakMap,Ir=new WeakMap,Kn=new WeakMap,Tr=new WeakMap,ge=new WeakMap,Mr=new WeakMap,Vn=new WeakMap,Jn=new WeakMap,We=new WeakMap,Xn=new WeakMap,Gn=new WeakMap,Yn=new WeakMap,Or=new WeakMap,Cr=new WeakMap,X=new WeakSet,li=function(){if(this.receivedMessages.length===0)throw new y("stream ended without producing a Message with role=assistant");return this.receivedMessages.at(-1)},la=function(){if(this.receivedMessages.length===0)throw new y("stream ended without producing a Message with role=assistant");let t=this.receivedMessages.at(-1).content.filter(r=>r.type==="text").map(r=>r.text);if(t.length===0)throw new y("stream ended without producing a content block with type=text");return t.join(" ")},ui=function(){this.ended||f(this,Te,void 0,"f")},di=function(t){if(this.ended)return;let r=a(this,X,"m",ua).call(this,t);switch(this._emit("streamEvent",t,r),t.type){case"content_block_delta":{let i=r.content.at(-1);switch(t.delta.type){case"text_delta":{i.type==="text"&&this._emit("text",t.delta.text,i.text||"");break}case"citations_delta":{i.type==="text"&&this._emit("citation",t.delta.citation,i.citations??[]);break}case"input_json_delta":{if(pi(i)&&a(this,ge,"f").inputJson?.length){let o;try{o=i.input}catch(c){a(this,Cr,"f").call(this,a(this,X,"m",fi).call(this,i,c));break}this._emit("inputJson",t.delta.partial_json,o)}break}case"thinking_delta":{i.type==="thinking"&&this._emit("thinking",t.delta.thinking,i.thinking);break}case"signature_delta":{i.type==="thinking"&&this._emit("signature",i.signature);break}case"compaction_delta":{i.type==="compaction"&&i.content&&this._emit("compaction",i.content);break}default:t.delta}break}case"message_stop":{this._addMessageParam(r),this._addMessage(ai(r,a(this,vt,"f"),{logger:a(this,Or,"f")}),!0);break}case"content_block_stop":{this._emit("contentBlock",r.content.at(-1));break}case"message_start":{f(this,Te,r,"f");break}case"content_block_start":case"message_delta":break}},hi=function(){if(this.ended)throw new y("stream has ended, this shouldn't happen");let t=a(this,Te,"f");if(!t)throw new y("request ended without sending any chunks");return f(this,Te,void 0,"f"),ai(t,a(this,vt,"f"),{logger:a(this,Or,"f")})},ua=function(t){let r=a(this,Te,"f");if(t.type==="message_start"){if(r)throw new y(`Unexpected event order, got ${t.type} before receiving "message_stop"`);return t.message}if(!r)throw new y(`Unexpected event order, got ${t.type} before "message_start"`);switch(t.type){case"message_stop":return r;case"message_delta":return r.stop_reason=t.delta.stop_reason,r.stop_sequence=t.delta.stop_sequence,r.stop_details=t.delta.stop_details,r.usage.output_tokens=t.usage.output_tokens,t.delta.container!=null&&(r.container=t.delta.container),t.context_management!=null&&(r.context_management=t.context_management),t.input_transformations!=null&&(r.input_transformations=t.input_transformations),t.usage.input_tokens!=null&&(r.usage.input_tokens=t.usage.input_tokens),t.usage.cache_creation_input_tokens!=null&&(r.usage.cache_creation_input_tokens=t.usage.cache_creation_input_tokens),t.usage.cache_read_input_tokens!=null&&(r.usage.cache_read_input_tokens=t.usage.cache_read_input_tokens),t.usage.server_tool_use!=null&&(r.usage.server_tool_use=t.usage.server_tool_use),t.usage.iterations!=null&&(r.usage.iterations=t.usage.iterations),t.usage.fallback_credit!=null&&(r.usage.fallback_credit=t.usage.fallback_credit),t.usage.output_tokens_details!=null&&(r.usage.output_tokens_details=t.usage.output_tokens_details),r;case"content_block_start":return r.content.push(t.content_block),t.content_block.type==="fallback"&&(r.model=t.content_block.to.model),r;case"content_block_delta":{let i=r.content.at(t.index);switch(t.delta.type){case"text_delta":{i?.type==="text"&&(r.content[t.index]={...i,text:(i.text||"")+t.delta.text});break}case"citations_delta":{i?.type==="text"&&(r.content[t.index]={...i,citations:[...i.citations??[],t.delta.citation]});break}case"input_json_delta":{if(i&&pi(i)){let o=(i[Ie]||"")+t.delta.partial_json;r.content[t.index]=Un(i,o)}break}case"thinking_delta":{i?.type==="thinking"&&(r.content[t.index]={...i,thinking:i.thinking+t.delta.thinking});break}case"signature_delta":{i?.type==="thinking"&&(r.content[t.index]={...i,signature:t.delta.signature});break}case"compaction_delta":{if(i?.type==="compaction"){let o={...i,content:t.delta.content};"encrypted_content"in t.delta&&(o.encrypted_content=t.delta.encrypted_content),r.content[t.index]=o}break}default:t.delta}return r}case"content_block_stop":{let i=r.content.at(t.index);if(i&&pi(i)&&Ie in i){let o;try{o=i.input}catch(c){o={},a(this,Cr,"f").call(this,a(this,X,"m",fi).call(this,i,c))}Object.defineProperty(i,"input",{value:o,enumerable:!0,configurable:!0,writable:!0})}return r}}},fi=function(t,r){let i=t[Ie];return new y(`Unable to parse tool parameter JSON from model. Please retry your request or adjust your prompt. Error: ${r}. JSON: ${i}`)},Symbol.asyncIterator)](){let e=[],t=[],r=!1;return this.on("streamEvent",i=>{let o=t.shift();o?o.resolve(i):e.push(i)}),this.on("end",()=>{r=!0;for(let i of t)i.resolve(void 0);t.length=0}),this.on("abort",i=>{r=!0;for(let o of t)o.reject(i);t.length=0}),this.on("error",i=>{r=!0;for(let o of t)o.reject(i);t.length=0}),{next:async()=>e.length?{value:e.shift(),done:!1}:r?{value:void 0,done:!0}:new Promise((o,c)=>t.push({resolve:o,reject:c})).then(o=>o?{value:o,done:!1}:{value:void 0,done:!0}),return:async()=>(this.abort(),{value:void 0,done:!0})}}toReadableStream(){return new _e(this[Symbol.asyncIterator].bind(this),this.controller).toReadableStream()}}return n})();var xe,Zn,je,At,es,qe,Rt,ts,da,rs,ns,mi=(()=>{class n extends Qn{constructor(e,t){super(e),xe.add(this),Zn.set(this,void 0),je.set(this,0),At.set(this,[]),es.set(this,[]),qe.set(this,void 0),Rt.set(this,[]),ts.set(this,!1),f(this,Zn,t,"f")}get toolCalls(){return a(this,es,"f")}static start(e,t,r,i){let o=new n({...t,stream:!0},i);for(let c of t.messages)o._addMessageParam(c);return o._run(()=>o._createMessage(e,{...t,stream:!0},{...r,headers:{...r?.headers,[nt]:"stream"}})),o}_emit(e,...t){var r;if(e!=="streamEvent"||this.ended){super._emit(e,...t);return}f(this,je,(r=a(this,je,"f"),r++,r),"f");let[i,o]=t,c=i.type==="content_block_stop"?o.content[i.index]:void 0,h=c?.type==="tool_use"?c:void 0;h&&a(this,es,"f").push(h),super._emit(e,...t),a(this,xe,"m",da).call(this,i,h),a(this,xe,"m",rs).call(this)}[(Zn=new WeakMap,je=new WeakMap,At=new WeakMap,es=new WeakMap,qe=new WeakMap,Rt=new WeakMap,ts=new WeakMap,xe=new WeakSet,Symbol.asyncIterator)](){let e=super[Symbol.asyncIterator](),t={handled:a(this,je,"f")};a(this,At,"f").push(t);let r=!1;return{next:async()=>{r&&(r=!1,t.handled++,a(this,xe,"m",rs).call(this));try{let i=await e.next();return r=!i.done,i.done&&a(this,xe,"m",ns).call(this,t),i}catch(i){throw a(this,xe,"m",ns).call(this,t),i}},return:async()=>{let i=e.return?.();return a(this,xe,"m",ns).call(this,t),await i??{value:void 0,done:!0}}}}}return da=function(e,t){if(a(this,ts,"f"))return;if(e.type==="content_block_start"&&e.content_block.type==="fallback"){f(this,ts,!0,"f"),f(this,qe,void 0,"f");return}let r=e.type==="content_block_start"||e.type==="message_delta"&&e.delta.stop_reason==="tool_use";a(this,qe,"f")&&r&&(a(this,Rt,"f").push({toolUse:a(this,qe,"f"),event:a(this,je,"f")}),f(this,qe,void 0,"f")),t&&f(this,qe,t,"f")},rs=function(){if(this.errored||this.controller.signal.aborted)return;let e=Math.min(a(this,je,"f"),...a(this,At,"f").map(t=>t.handled));for(;a(this,Rt,"f")[0]&&a(this,Rt,"f")[0].event<=e;)a(this,Zn,"f").call(this,a(this,Rt,"f").shift().toolUse)},ns=function(e){let t=a(this,At,"f").indexOf(e);t>=0&&(a(this,At,"f").splice(t,1),a(this,xe,"m",rs).call(this))},n})();var L,Et,Ue,N,G,Y,Me,we,Oe,$r,re,be,Pt,It,ze,_i,ha,gi,wi,Nr,ss,fa,bi,yi,pa,ki,xi=(()=>{class n{constructor(e,t,r){L.add(this),this.client=e,Et.set(this,!1),Ue.set(this,!1),N.set(this,void 0),G.set(this,void 0),Y.set(this,void 0),Me.set(this,void 0),we.set(this,void 0),Oe.set(this,void 0),$r.set(this,0),re.set(this,{status:"idle"}),be.set(this,void 0),Pt.set(this,null),It.set(this,new Map),ze.set(this,[]),ma(t),hl(t),_a(t),f(this,N,{params:{...t,messages:JSON.parse(JSON.stringify(t.messages))}},"f");let i=Qs(t.tools,t.messages);f(this,G,{...r,headers:l([_n("BetaToolRunner"),i.length?{[Be]:i.join(", ")}:void 0,r?.headers])},"f"),f(this,Oe,Rs(),"f")}async*[(Et=new WeakMap,Ue=new WeakMap,N=new WeakMap,G=new WeakMap,Y=new WeakMap,Me=new WeakMap,we=new WeakMap,Oe=new WeakMap,$r=new WeakMap,re=new WeakMap,be=new WeakMap,Pt=new WeakMap,It=new WeakMap,ze=new WeakMap,L=new WeakSet,Symbol.asyncIterator)](){var e;if(a(this,Et,"f"))throw new y("Cannot iterate over a consumed stream");f(this,Et,!0,"f"),f(this,Ue,!0,"f"),f(this,we,void 0,"f");try{for(;;)try{if(a(this,N,"f").params.max_iterations&&a(this,$r,"f")>=a(this,N,"f").params.max_iterations)break;if(a(this,L,"m",pa).call(this),a(this,re,"f").status==="scheduled"&&wa(a(this,Pt,"f"))!=="resume"){yield*a(this,L,"m",wi).call(this,a(this,re,"f").config);continue}f(this,Ue,!1,"f"),f(this,we,void 0,"f"),f(this,$r,(e=a(this,$r,"f"),e++,e),"f"),f(this,Y,void 0,"f");let{max_iterations:t,runToolsEagerly:r,...i}=a(this,N,"f").params;if(yield*a(this,L,"m",_i).call(this,i),a(this,Ue,"f"))f(this,Pt,null,"f");else{let c=await a(this,Y,"f"),h=wa(c.stop_reason);f(this,Pt,c.stop_reason,"f"),a(this,N,"f").params.messages.push({role:c.role,content:c.content});let{container:u}=a(this,N,"f").params;if(c.container&&(u==null?a(this,N,"f").params.container=c.container.id:typeof u=="object"&&u.id==null&&(a(this,N,"f").params.container={...u,id:c.container.id})),h==="stop"){yield*a(this,L,"m",bi).call(this);break}if(h==="resume")continue}let o=await a(this,L,"m",yi).call(this,a(this,N,"f").params.messages.at(-1));if(o)a(this,N,"f").params.messages.push(o);else if(!a(this,Ue,"f")){yield*a(this,L,"m",bi).call(this);break}}finally{a(this,Me,"f")?.abort(),f(this,Me,void 0,"f")}if(await a(this,L,"m",gi).call(this),!a(this,Y,"f"))throw new y("ToolRunner concluded without a message from the server");a(this,Oe,"f").resolve(await a(this,Y,"f"))}catch(t){throw f(this,Et,!1,"f"),a(this,Oe,"f").promise.catch(()=>{}),a(this,Oe,"f").reject(t),f(this,Oe,Rs(),"f"),t}}setMessagesParams(e){let t=typeof e=="function"?e(a(this,N,"f").params):e;if(ma(t),_a(t),a(this,re,"f").status!=="idle"&&Si(t),a(this,re,"f").status==="in_flight"&&t.messages!==a(this,N,"f").params.messages)throw new y("Message params can't be changed while the conversation is being compacted, because the compaction response is about to replace them. Change them after this iteration instead.");a(this,N,"f").params=t,f(this,Ue,!0,"f"),f(this,we,void 0,"f")}setRequestOptions(e){typeof e=="function"?f(this,G,e(a(this,G,"f")),"f"):f(this,G,{...a(this,G,"f"),...e},"f")}async generateToolResponse(e=a(this,G,"f").signal){let t=await a(this,Y,"f")??this.params.messages.at(-1);return t?a(this,L,"m",yi).call(this,t,e):null}deferToolCall(e){let t=typeof e=="string"?e:e.id;a(this,be,"f")&&!a(this,be,"f").has(t)&&a(this,be,"f").set(t,{status:"held"})}get deferredToolCalls(){let e=a(this,Me,"f"),t=a(this,be,"f");return!(e instanceof mi)||!t?[]:e.toolCalls.filter(r=>t.get(r.id)?.status==="held")}done(){return a(this,Oe,"f").promise}async runUntilDone(){if(!a(this,Et,"f"))for await(let e of this);return this.done()}get params(){return a(this,N,"f").params}pushMessages(...e){this.setMessagesParams(t=>({...t,messages:[...t.messages,...e]}))}compactBeforeNextTurn(e){a(this,re,"f").status!=="in_flight"&&(Si(a(this,N,"f").params),f(this,re,{status:"scheduled",config:e??{type:"summarize"}},"f"))}addTools(...e){for(let t of e)"name"in t&&a(this,It,"f").set(t.name,"run"in t?t:null),a(this,ze,"f").push({type:"addition",tool:t})}removeTools(...e){for(let t of e){let r=typeof t=="string"?t:t.name;a(this,It,"f").set(r,null),a(this,ze,"f").push({type:"removal",name:r})}}then(e,t){return this.runUntilDone().then(e,t)}}return _i=async function*(e){await a(this,L,"m",gi).call(this),f(this,be,void 0,"f"),e.stream?(f(this,Me,a(this,N,"f").params.runToolsEagerly?a(this,L,"m",ha).call(this,e):this.client.beta.messages.stream({...e},a(this,G,"f")),"f"),f(this,Y,a(this,Me,"f").finalMessage(),"f"),a(this,Y,"f").catch(()=>{}),yield a(this,Me,"f")):(f(this,Y,this.client.beta.messages.create({...e,stream:!1},a(this,G,"f")),"f"),yield a(this,Y,"f"))},ha=function(e){let t=new Map;return f(this,be,t,"f"),mi.start(this.client.beta.messages,e,a(this,G,"f"),r=>{if(t.has(r.id))return;let i=ba(a(this,L,"m",Nr).call(this),a(this,L,"m",ss).call(this),r,a(this,G,"f"));i.catch(()=>{}),t.set(r.id,{status:"started",result:i})})},gi=async function(){let e=[...a(this,be,"f")?.values()??[]].filter(t=>t.status==="started");await Promise.allSettled(e.map(t=>t.result))},wi=async function*(e){Si(a(this,N,"f").params);let{max_iterations:t,runToolsEagerly:r,...i}=a(this,N,"f").params,o=fl(i);f(this,re,{status:"in_flight"},"f"),f(this,we,void 0,"f");let c=a(this,Y,"f");try{yield*a(this,L,"m",_i).call(this,{...o,compaction:e});let h=await a(this,Y,"f");h.content.some(u=>u.type==="compaction"&&u.content)?(a(this,L,"m",fa).call(this),a(this,N,"f").params.messages=[{role:h.role,content:h.content}]):(T(this.client).warn("Compaction produced no summary; keeping the conversation as it is."),f(this,Y,c,"f"))}finally{f(this,re,{status:"idle"},"f")}},Nr=function(){let e=new Map;for(let t of a(this,N,"f").params.tools)"run"in t&&e.set(t.name,t);for(let[t,r]of a(this,It,"f"))r?e.set(t,r):e.delete(t);return e},ss=function(){let e=new Set(a(this,L,"m",Nr).call(this).keys());for(let t of[...a(this,N,"f").params.messages,a(this,L,"m",ki).call(this)])if(typeof t.content!="string"){for(let r of t.content)if(t.role==="system")ga(r,e);else if(t.role==="assistant"&&r.type==="compaction")for(let i of r.tool_changes??[])ga(i,e)}return e},fa=function(){let e=a(this,L,"m",ss).call(this);for(let t of a(this,L,"m",Nr).call(this).keys())e.has(t)||a(this,It,"f").set(t,null)},bi=async function*(){if(a(this,re,"f").status!=="scheduled")return;let e=a(this,N,"f").params.messages.at(-1)?.content;if(Array.isArray(e)&&e.some(t=>t.type==="tool_use")){T(this.client).warn("The pending compaction was skipped because the last turn ended with tool calls that were not run. Call `compactBeforeNextTurn()` again if you continue the conversation."),f(this,re,{status:"idle"},"f");return}yield*a(this,L,"m",wi).call(this,a(this,re,"f").config)},yi=async function(e,t=a(this,G,"f").signal){return a(this,we,"f")!==void 0?a(this,we,"f"):(f(this,we,pl(a(this,L,"m",Nr).call(this),a(this,L,"m",ss).call(this),e,{...a(this,G,"f"),signal:t},a(this,be,"f")),"f"),a(this,we,"f"))},pa=function(){a(this,Pt,"f")==="pause_turn"||a(this,ze,"f").length===0||(a(this,N,"f").params.messages.push(a(this,L,"m",ki).call(this)),f(this,ze,[],"f"))},ki=function(){let e=[];for(let t of a(this,ze,"f")){if(t.type==="removal"){e.push({type:"tool_removal",tool:{type:"tool_reference",name:t.name}});continue}let r=t.tool;if("run"in t.tool){let{run:i,parse:o,close:c,...h}=t.tool;r=h}e.push({type:"tool_addition",tool:{type:"tool_definition",definition:r}})}return{role:"system",content:e}},n})();function ma(n){if("compaction"in n&&n.compaction!=null)throw new y("`compaction` cannot be set on a tool runner: every request in the loop would compact again. Call `runner.compactBeforeNextTurn()` when the conversation should be compacted instead.")}function hl(n){if("compactionControl"in n&&n.compactionControl!=null)throw new y("`compactionControl` has been removed from the tool runner. Use server-side compaction instead: call `runner.compactBeforeNextTurn()` when the conversation should be compacted.")}function _a(n){if(n.runToolsEagerly&&!n.stream)throw new TypeError("`runToolsEagerly: true` needs `stream: true` in the tool runner's params, because a reply that isn't streamed arrives whole.")}function Si(n){if(n.context_management?.edits?.some(s=>s.type.startsWith("compact_")))throw new y("`compactBeforeNextTurn()` can't be used while `context_management` has a compaction edit, because the API doesn't accept a compaction block together with one. Remove the edit first.")}function fl(n){let{context_management:s,stop_sequences:e,output_format:t,...r}=n,i=({format:o,...c})=>c;return(r.tool_choice?.type==="any"||r.tool_choice?.type==="tool")&&delete r.tool_choice,r.output_config&&(r.output_config=i(r.output_config)),Array.isArray(r.fallbacks)&&(r.fallbacks=r.fallbacks.map(o=>o.output_config?{...o,output_config:i(o.output_config)}:o)),r}async function pl(n,s,e,t,r){if(!e||e.role!=="assistant"||!e.content||typeof e.content=="string")return null;let i=e.content.filter(c=>c.type==="tool_use");return i.length===0?null:{role:"user",content:await Promise.all(i.map(c=>{let h=r?.get(c.id);if(h?.status==="started")return h.result;let u=ba(n,s,c,t);return r?.set(c.id,{status:"started",result:u}),u}))}}async function ba(n,s,e,t){let r=s.has(e.name)?n.get(e.name):void 0;if(!r)return ml(e);try{let i=e.input;"parse"in r&&r.parse&&(i=r.parse(i));let o=await r.run(i,{toolUse:e,toolUseBlock:e,signal:t?.signal});return{type:"tool_result",tool_use_id:e.id,content:o}}catch(i){return{type:"tool_result",tool_use_id:e.id,content:i instanceof Ge?i.content:`Error: ${i instanceof Error?i.message:String(i)}`,is_error:!0}}}function ml(n){return{type:"tool_result",tool_use_id:n.id,content:`Error: Tool '${n.name}' not found`,is_error:!0}}function ga(n,s){switch(n.type){case"tool_removal":case"tool_addition":_l(n,s);break}}function _l(n,s){let e=gl(n.tool);e!==void 0&&(n.type==="tool_removal"?s.delete(e):s.add(e))}function gl(n){switch(n.type){case"tool_reference":return n.name;case"tool_definition":return"name"in n.definition?n.definition.name:void 0;default:return}}function wa(n){if(n===null)return"stop";switch(n){case"tool_use":return"run_tools";case"pause_turn":case"compaction":return"resume";case"end_turn":case"stop_sequence":case"max_tokens":case"model_context_window_exceeded":case"refusal":return"stop";default:return"stop"}}var ya={},wl=["claude-mythos-preview","claude-opus-4-6"],is=(()=>{class n extends w{constructor(){super(...arguments),this.batches=new xt(this._client)}create(e,t){let r=ka(e),{betas:i,user_profile_id:o,workspace_id:c,...h}=r;h.model in ya&&console.warn(`The model '${h.model}' is deprecated and will reach end-of-life on ${ya[h.model]}
|
|
13
13
|
Please migrate to a newer model. Visit https://docs.anthropic.com/en/docs/resources/model-deprecations for more information.`),wl.includes(h.model)&&h.thinking&&h.thinking.type==="enabled"&&console.warn(`Using Claude with ${h.model} and 'thinking.type=enabled' is deprecated. Use 'thinking.type=adaptive' instead which results in better model performance in our testing: https://platform.claude.com/docs/en/build-with-claude/adaptive-thinking`);let u=t?.timeout??this._client._options.timeout;if(!h.stream&&u==null){let p=qn[h.model]??void 0;u=this._client.calculateNonstreamingTimeout(h.max_tokens,p)}let g=gn(h.tools,h.messages);return this._client.post("/v1/messages?beta=true",{body:h,timeout:u??6e5,...t,headers:l([{...i?.toString()!=null?{"anthropic-beta":i?.toString()}:void 0,...o!=null?{"anthropic-user-profile-id":o}:void 0,...c!=null?{"anthropic-workspace-id":c}:void 0},g,t?.headers]),stream:r.stream??!1})}parse(e,t){return t={...t,headers:l([{"anthropic-beta":[...e.betas??[],"structured-outputs-2025-12-15"].toString()},t?.headers])},this.create(e,t).then(r=>ci(r,e,{logger:this._client.logger??console}))}stream(e,t){return Qn.createMessage(this,e,t)}countTokens(e,t){let r=ka(e),{betas:i,user_profile_id:o,workspace_id:c,...h}=r;return this._client.post("/v1/messages/count_tokens?beta=true",{body:h,...t,headers:l([{"anthropic-beta":[...i??[],"token-counting-2024-11-01"].toString(),...o!=null?{"anthropic-user-profile-id":o}:void 0,...c!=null?{"anthropic-workspace-id":c}:void 0},t?.headers])})}toolRunner(e,t){return new xi(this._client,e,t)}}return n.Batches=xt,n.BetaToolRunner=xi,n.ToolError=Ge,n})();function ka(n){if(!n.output_format)return n;if(n.output_config?.format)throw new y("Both output_format and output_config.format were provided. Please use only output_config.format (output_format is deprecated).");let{output_format:s,...e}=n;return{...e,output_config:{...n.output_config,format:s}}}var Tt=class extends w{retrieve(s,e){return this._client.get(d`/v1/organizations/api_keys/${s}?beta=true`,e)}update(s,e,t){return this._client.post(d`/v1/organizations/api_keys/${s}?beta=true`,{body:e,...t})}list(s={},e){return this._client.getAPIList("/v1/organizations/api_keys?beta=true",W,{query:s,...e})}};var Mt=class extends w{retrieve(s){return this._client.get("/v1/organizations/compliance_settings?beta=true",s)}update(s,e){return this._client.post("/v1/organizations/compliance_settings?beta=true",{body:s,...e})}};var Ot=class extends w{create(s,e){return this._client.post("/v1/organizations/external_keys?beta=true",{body:s,...e})}retrieve(s,e){return this._client.get(d`/v1/organizations/external_keys/${s}?beta=true`,e)}update(s,e,t){return this._client.post(d`/v1/organizations/external_keys/${s}?beta=true`,{body:e,...t})}list(s={},e){return this._client.getAPIList("/v1/organizations/external_keys?beta=true",S,{query:s,...e})}delete(s,e){return this._client.delete(d`/v1/organizations/external_keys/${s}?beta=true`,e)}validate(s,e){return this._client.post(d`/v1/organizations/external_keys/${s}/validate?beta=true`,e)}};var Ct=class extends w{create(s,e){return this._client.post("/v1/organizations/invites?beta=true",{body:s,...e})}retrieve(s,e){return this._client.get(d`/v1/organizations/invites/${s}?beta=true`,e)}list(s={},e){return this._client.getAPIList("/v1/organizations/invites?beta=true",W,{query:s,...e})}delete(s,e){return this._client.delete(d`/v1/organizations/invites/${s}?beta=true`,e)}};var $t=class extends w{list(s={},e){return this._client.getAPIList("/v1/organizations/rate_limits?beta=true",S,{query:s,...e})}};var Nt=class extends w{retrieve(s,e){return this._client.get(d`/v1/organizations/users/${s}?beta=true`,e)}update(s,e,t){return this._client.post(d`/v1/organizations/users/${s}?beta=true`,{body:e,...t})}list(s={},e){return this._client.getAPIList("/v1/organizations/users?beta=true",W,{query:s,...e})}remove(s,e){return this._client.delete(d`/v1/organizations/users/${s}?beta=true`,e)}};var Lt=class extends w{create(s,e){let{betas:t,...r}=s;return this._client.post("/v1/organizations/federation_issuers?beta=true",{body:r,...e,headers:l([{...t?.toString()!=null?{"anthropic-beta":t?.toString()}:void 0},e?.headers])})}retrieve(s,e={},t){let{betas:r}=e??{};return this._client.get(d`/v1/organizations/federation_issuers/${s}?beta=true`,{...t,headers:l([{...r?.toString()!=null?{"anthropic-beta":r?.toString()}:void 0},t?.headers])})}update(s,e,t){let{betas:r,...i}=e;return this._client.post(d`/v1/organizations/federation_issuers/${s}?beta=true`,{body:i,...t,headers:l([{...r?.toString()!=null?{"anthropic-beta":r?.toString()}:void 0},t?.headers])})}list(s={},e){let{betas:t,...r}=s??{};return this._client.getAPIList("/v1/organizations/federation_issuers?beta=true",S,{query:r,...e,headers:l([{...t?.toString()!=null?{"anthropic-beta":t?.toString()}:void 0},e?.headers])})}archive(s,e={},t){let{betas:r}=e??{};return this._client.post(d`/v1/organizations/federation_issuers/${s}/archive?beta=true`,{...t,headers:l([{...r?.toString()!=null?{"anthropic-beta":r?.toString()}:void 0},t?.headers])})}};var Ft=class extends w{list(s,e={},t){let{betas:r,...i}=e??{};return this._client.getAPIList(d`/v1/organizations/federation_rules/${s}/workspaces?beta=true`,S,{query:i,...t,headers:l([{...r?.toString()!=null?{"anthropic-beta":r?.toString()}:void 0},t?.headers])})}add(s,e,t){let{betas:r,...i}=e;return this._client.post(d`/v1/organizations/federation_rules/${s}/workspaces?beta=true`,{body:i,...t,headers:l([{...r?.toString()!=null?{"anthropic-beta":r?.toString()}:void 0},t?.headers])})}remove(s,e,t){let{federation_rule_id:r,betas:i}=e;return this._client.delete(d`/v1/organizations/federation_rules/${r}/workspaces/${s}?beta=true`,{...t,headers:l([{...i?.toString()!=null?{"anthropic-beta":i?.toString()}:void 0},t?.headers])})}};var os=(()=>{class n extends w{constructor(){super(...arguments),this.workspaces=new Ft(this._client)}create(e,t){let{betas:r,...i}=e;return this._client.post("/v1/organizations/federation_rules?beta=true",{body:i,...t,headers:l([{...r?.toString()!=null?{"anthropic-beta":r?.toString()}:void 0},t?.headers])})}retrieve(e,t={},r){let{betas:i}=t??{};return this._client.get(d`/v1/organizations/federation_rules/${e}?beta=true`,{...r,headers:l([{...i?.toString()!=null?{"anthropic-beta":i?.toString()}:void 0},r?.headers])})}update(e,t,r){let{betas:i,...o}=t;return this._client.post(d`/v1/organizations/federation_rules/${e}?beta=true`,{body:o,...r,headers:l([{...i?.toString()!=null?{"anthropic-beta":i?.toString()}:void 0},r?.headers])})}list(e={},t){let{betas:r,...i}=e??{};return this._client.getAPIList("/v1/organizations/federation_rules?beta=true",S,{query:i,...t,headers:l([{...r?.toString()!=null?{"anthropic-beta":r?.toString()}:void 0},t?.headers])})}archive(e,t={},r){let{betas:i}=t??{};return this._client.post(d`/v1/organizations/federation_rules/${e}/archive?beta=true`,{...r,headers:l([{...i?.toString()!=null?{"anthropic-beta":i?.toString()}:void 0},r?.headers])})}}return n.Workspaces=Ft,n})();var as=(()=>{class n extends w{constructor(){super(...arguments),this.issuers=new Lt(this._client),this.rules=new os(this._client)}}return n.Issuers=Lt,n.Rules=os,n})();var Bt=class extends w{list(s,e={},t){let{betas:r,...i}=e??{};return this._client.getAPIList(d`/v1/organizations/service_accounts/${s}/workspaces?beta=true`,S,{query:i,...t,headers:l([{...r?.toString()!=null?{"anthropic-beta":r?.toString()}:void 0},t?.headers])})}add(s,e,t){let{betas:r,...i}=e;return this._client.post(d`/v1/organizations/service_accounts/${s}/workspaces?beta=true`,{body:i,...t,headers:l([{...r?.toString()!=null?{"anthropic-beta":r?.toString()}:void 0},t?.headers])})}remove(s,e,t){let{service_account_id:r,betas:i}=e;return this._client.delete(d`/v1/organizations/service_accounts/${r}/workspaces/${s}?beta=true`,{...t,headers:l([{...i?.toString()!=null?{"anthropic-beta":i?.toString()}:void 0},t?.headers])})}};var cs=(()=>{class n extends w{constructor(){super(...arguments),this.workspaces=new Bt(this._client)}create(e,t){let{betas:r,...i}=e;return this._client.post("/v1/organizations/service_accounts?beta=true",{body:i,...t,headers:l([{...r?.toString()!=null?{"anthropic-beta":r?.toString()}:void 0},t?.headers])})}retrieve(e,t={},r){let{betas:i}=t??{};return this._client.get(d`/v1/organizations/service_accounts/${e}?beta=true`,{...r,headers:l([{...i?.toString()!=null?{"anthropic-beta":i?.toString()}:void 0},r?.headers])})}update(e,t,r){let{betas:i,...o}=t;return this._client.post(d`/v1/organizations/service_accounts/${e}?beta=true`,{body:o,...r,headers:l([{...i?.toString()!=null?{"anthropic-beta":i?.toString()}:void 0},r?.headers])})}list(e={},t){let{betas:r,...i}=e??{};return this._client.getAPIList("/v1/organizations/service_accounts?beta=true",S,{query:i,...t,headers:l([{...r?.toString()!=null?{"anthropic-beta":r?.toString()}:void 0},t?.headers])})}archive(e,t={},r){let{betas:i}=t??{};return this._client.post(d`/v1/organizations/service_accounts/${e}/archive?beta=true`,{...r,headers:l([{...i?.toString()!=null?{"anthropic-beta":i?.toString()}:void 0},r?.headers])})}}return n.Workspaces=Bt,n})();var Ht=class extends w{retrieve(s,e,t){let{workspace_id:r}=e;return this._client.get(d`/v1/organizations/workspaces/${r}/members/${s}?beta=true`,t)}update(s,e,t){let{workspace_id:r,...i}=e;return this._client.post(d`/v1/organizations/workspaces/${r}/members/${s}?beta=true`,{body:i,...t})}list(s,e={},t){return this._client.getAPIList(d`/v1/organizations/workspaces/${s}/members?beta=true`,W,{query:e,...t})}add(s,e,t){return this._client.post(d`/v1/organizations/workspaces/${s}/members?beta=true`,{body:e,...t})}remove(s,e,t){let{workspace_id:r}=e;return this._client.delete(d`/v1/organizations/workspaces/${r}/members/${s}?beta=true`,t)}};var Dt=class extends w{list(s,e={},t){return this._client.getAPIList(d`/v1/organizations/workspaces/${s}/rate_limits?beta=true`,S,{query:e,...t})}};var Wt=class extends w{retrieve(s,e,t){let{workspace_id:r,betas:i}=e;return this._client.get(d`/v1/organizations/workspaces/${r}/service_accounts/${s}?beta=true`,{...t,headers:l([{...i?.toString()!=null?{"anthropic-beta":i?.toString()}:void 0},t?.headers])})}update(s,e,t){let{workspace_id:r,betas:i,...o}=e;return this._client.post(d`/v1/organizations/workspaces/${r}/service_accounts/${s}?beta=true`,{body:o,...t,headers:l([{...i?.toString()!=null?{"anthropic-beta":i?.toString()}:void 0},t?.headers])})}list(s,e={},t){let{betas:r,...i}=e??{};return this._client.getAPIList(d`/v1/organizations/workspaces/${s}/service_accounts?beta=true`,S,{query:i,...t,headers:l([{...r?.toString()!=null?{"anthropic-beta":r?.toString()}:void 0},t?.headers])})}add(s,e,t){let{betas:r,...i}=e;return this._client.post(d`/v1/organizations/workspaces/${s}/service_accounts?beta=true`,{body:i,...t,headers:l([{...r?.toString()!=null?{"anthropic-beta":r?.toString()}:void 0},t?.headers])})}remove(s,e,t){let{workspace_id:r,betas:i}=e;return this._client.delete(d`/v1/organizations/workspaces/${r}/service_accounts/${s}?beta=true`,{...t,headers:l([{...i?.toString()!=null?{"anthropic-beta":i?.toString()}:void 0},t?.headers])})}};var ls=(()=>{class n extends w{constructor(){super(...arguments),this.rateLimits=new Dt(this._client),this.members=new Ht(this._client),this.serviceAccounts=new Wt(this._client)}create(e,t){let{betas:r,...i}=e;return this._client.post("/v1/organizations/workspaces?beta=true",{body:i,...t,headers:l([{...r?.toString()!=null?{"anthropic-beta":r?.toString()}:void 0},t?.headers])})}retrieve(e,t){return this._client.get(d`/v1/organizations/workspaces/${e}?beta=true`,t)}update(e,t,r){return this._client.post(d`/v1/organizations/workspaces/${e}?beta=true`,{body:t,...r})}list(e={},t){return this._client.getAPIList("/v1/organizations/workspaces?beta=true",W,{query:e,...t})}archive(e,t){return this._client.post(d`/v1/organizations/workspaces/${e}/archive?beta=true`,t)}}return n.RateLimits=Dt,n.Members=Ht,n.ServiceAccounts=Wt,n})();var us=(()=>{class n extends w{constructor(){super(...arguments),this.apiKeys=new Tt(this._client),this.externalKeys=new Ot(this._client),this.federation=new as(this._client),this.invites=new Ct(this._client),this.serviceAccounts=new cs(this._client),this.users=new Nt(this._client),this.workspaces=new ls(this._client),this.rateLimits=new $t(this._client),this.complianceSettings=new Mt(this._client)}retrieve(e){return this._client.get("/v1/organizations/me?beta=true",e)}}return n.APIKeys=Tt,n.ExternalKeys=Ot,n.Federation=as,n.Invites=Ct,n.ServiceAccounts=cs,n.Users=Nt,n.Workspaces=ls,n.RateLimits=$t,n.ComplianceSettings=Mt,n})();var ds=(()=>{class n extends w{list(e,t={},r){let{betas:i,workspace_id:o,...c}=t??{};return this._client.getAPIList(d`/v1/sessions/${e}/events?beta=true`,S,{query:c,...r,headers:l([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...o!=null?{"anthropic-workspace-id":o}:void 0},r?.headers])})}send(e,t,r){let{betas:i,workspace_id:o,...c}=t;return this._client.post(d`/v1/sessions/${e}/events?beta=true`,{body:c,...r,headers:l([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...o!=null?{"anthropic-workspace-id":o}:void 0},r?.headers])})}stream(e,t={},r){let{betas:i,workspace_id:o,...c}=t??{};return this._client.get(d`/v1/sessions/${e}/events/stream?beta=true`,{query:c,...r,headers:l([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...o!=null?{"anthropic-workspace-id":o}:void 0},r?.headers]),stream:!0})}toolRunner(e,t){return new vr(e,{...t,client:this._client})}}return n.SessionToolRunner=vr,n})();var jt=class extends w{retrieve(s,e,t){let{session_id:r,betas:i,workspace_id:o}=e;return this._client.get(d`/v1/sessions/${r}/resources/${s}?beta=true`,{...t,headers:l([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...o!=null?{"anthropic-workspace-id":o}:void 0},t?.headers])})}update(s,e,t){let{session_id:r,betas:i,workspace_id:o,...c}=e;return this._client.post(d`/v1/sessions/${r}/resources/${s}?beta=true`,{body:c,...t,headers:l([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...o!=null?{"anthropic-workspace-id":o}:void 0},t?.headers])})}list(s,e={},t){let{betas:r,workspace_id:i,...o}=e??{};return this._client.getAPIList(d`/v1/sessions/${s}/resources?beta=true`,S,{query:o,...t,headers:l([{"anthropic-beta":[...r??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}delete(s,e,t){let{session_id:r,betas:i,workspace_id:o}=e;return this._client.delete(d`/v1/sessions/${r}/resources/${s}?beta=true`,{...t,headers:l([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...o!=null?{"anthropic-workspace-id":o}:void 0},t?.headers])})}add(s,e,t){let{betas:r,workspace_id:i,...o}=e;return this._client.post(d`/v1/sessions/${s}/resources?beta=true`,{body:o,...t,headers:l([{"anthropic-beta":[...r??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}};var qt=class extends w{list(s,e,t){let{session_id:r,betas:i,workspace_id:o,...c}=e;return this._client.getAPIList(d`/v1/sessions/${r}/threads/${s}/events?beta=true`,S,{query:c,...t,headers:l([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...o!=null?{"anthropic-workspace-id":o}:void 0},t?.headers])})}stream(s,e,t){let{session_id:r,betas:i,workspace_id:o,...c}=e;return this._client.get(d`/v1/sessions/${r}/threads/${s}/stream?beta=true`,{query:c,...t,headers:l([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...o!=null?{"anthropic-workspace-id":o}:void 0},t?.headers]),stream:!0})}};var hs=(()=>{class n extends w{constructor(){super(...arguments),this.events=new qt(this._client)}retrieve(e,t,r){let{session_id:i,betas:o,workspace_id:c}=t;return this._client.get(d`/v1/sessions/${i}/threads/${e}?beta=true`,{...r,headers:l([{"anthropic-beta":[...o??[],"managed-agents-2026-04-01"].toString(),...c!=null?{"anthropic-workspace-id":c}:void 0},r?.headers])})}list(e,t={},r){let{betas:i,workspace_id:o,...c}=t??{};return this._client.getAPIList(d`/v1/sessions/${e}/threads?beta=true`,S,{query:c,...r,headers:l([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...o!=null?{"anthropic-workspace-id":o}:void 0},r?.headers])})}archive(e,t,r){let{session_id:i,betas:o,workspace_id:c}=t;return this._client.post(d`/v1/sessions/${i}/threads/${e}/archive?beta=true`,{...r,headers:l([{"anthropic-beta":[...o??[],"managed-agents-2026-04-01"].toString(),...c!=null?{"anthropic-workspace-id":c}:void 0},r?.headers])})}}return n.Events=qt,n})();var fs=(()=>{class n extends w{constructor(){super(...arguments),this.events=new ds(this._client),this.resources=new jt(this._client),this.threads=new hs(this._client)}create(e,t){let{betas:r,workspace_id:i,...o}=e;return this._client.post("/v1/sessions?beta=true",{body:o,...t,headers:l([{"anthropic-beta":[...r??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}retrieve(e,t={},r){let{betas:i,workspace_id:o}=t??{};return this._client.get(d`/v1/sessions/${e}?beta=true`,{...r,headers:l([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...o!=null?{"anthropic-workspace-id":o}:void 0},r?.headers])})}update(e,t,r){let{betas:i,workspace_id:o,...c}=t;return this._client.post(d`/v1/sessions/${e}?beta=true`,{body:c,...r,headers:l([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...o!=null?{"anthropic-workspace-id":o}:void 0},r?.headers])})}list(e={},t){let{betas:r,workspace_id:i,...o}=e??{};return this._client.getAPIList("/v1/sessions?beta=true",pn,{query:o,...t,headers:l([{"anthropic-beta":[...r??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}delete(e,t={},r){let{betas:i,workspace_id:o}=t??{};return this._client.delete(d`/v1/sessions/${e}?beta=true`,{...r,headers:l([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...o!=null?{"anthropic-workspace-id":o}:void 0},r?.headers])})}archive(e,t={},r){let{betas:i,workspace_id:o}=t??{};return this._client.post(d`/v1/sessions/${e}/archive?beta=true`,{...r,headers:l([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...o!=null?{"anthropic-workspace-id":o}:void 0},r?.headers])})}}return n.Events=ds,n.Resources=jt,n.Threads=hs,n})();var Ut=class extends w{create(s,e,t){let{betas:r,workspace_id:i,...o}=e;return this._client.post(d`/v1/skills/${s}/versions?beta=true`,ie({body:o,...t,headers:l([{...r?.toString()!=null?{"anthropic-beta":r?.toString()}:void 0,...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])},this._client,!1))}retrieve(s,e,t){let{skill_id:r,betas:i,workspace_id:o}=e;return this._client.get(d`/v1/skills/${r}/versions/${s}?beta=true`,{...t,headers:l([{...i?.toString()!=null?{"anthropic-beta":i?.toString()}:void 0,...o!=null?{"anthropic-workspace-id":o}:void 0},t?.headers])})}list(s,e={},t){let{betas:r,workspace_id:i,...o}=e??{};return this._client.getAPIList(d`/v1/skills/${s}/versions?beta=true`,S,{query:o,...t,headers:l([{...r?.toString()!=null?{"anthropic-beta":r?.toString()}:void 0,...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}delete(s,e,t){let{skill_id:r,betas:i,workspace_id:o}=e;return this._client.delete(d`/v1/skills/${r}/versions/${s}?beta=true`,{...t,headers:l([{...i?.toString()!=null?{"anthropic-beta":i?.toString()}:void 0,...o!=null?{"anthropic-workspace-id":o}:void 0},t?.headers])})}download(s,e,t){let{skill_id:r,betas:i,workspace_id:o}=e;return this._client.get(d`/v1/skills/${r}/versions/${s}/content?beta=true`,{...t,headers:l([{Accept:"application/binary",...i?.toString()!=null?{"anthropic-beta":i?.toString()}:void 0,...o!=null?{"anthropic-workspace-id":o}:void 0},t?.headers]),__binaryResponse:!0})}};var ps=(()=>{class n extends w{constructor(){super(...arguments),this.versions=new Ut(this._client)}create(e,t){let{betas:r,workspace_id:i,...o}=e;return this._client.post("/v1/skills?beta=true",ie({body:o,...t,headers:l([{...r?.toString()!=null?{"anthropic-beta":r?.toString()}:void 0,...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])},this._client,!1))}retrieve(e,t={},r){let{betas:i,workspace_id:o}=t??{};return this._client.get(d`/v1/skills/${e}?beta=true`,{...r,headers:l([{...i?.toString()!=null?{"anthropic-beta":i?.toString()}:void 0,...o!=null?{"anthropic-workspace-id":o}:void 0},r?.headers])})}list(e={},t){let{betas:r,workspace_id:i,...o}=e??{};return this._client.getAPIList("/v1/skills?beta=true",S,{query:o,...t,headers:l([{...r?.toString()!=null?{"anthropic-beta":r?.toString()}:void 0,...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}delete(e,t={},r){let{betas:i,workspace_id:o}=t??{};return this._client.delete(d`/v1/skills/${e}?beta=true`,{...r,headers:l([{...i?.toString()!=null?{"anthropic-beta":i?.toString()}:void 0,...o!=null?{"anthropic-workspace-id":o}:void 0},r?.headers])})}}return n.Versions=Ut,n})();var zt=class extends w{create(s,e,t){let{betas:r,workspace_id:i,...o}=e;return this._client.post(d`/v1/tunnels/${s}/certificates?beta=true`,{body:o,...t,headers:l([{"anthropic-beta":[...r??[],"mcp-tunnels-2026-06-22"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}retrieve(s,e,t){let{tunnel_id:r,betas:i,workspace_id:o}=e;return this._client.get(d`/v1/tunnels/${r}/certificates/${s}?beta=true`,{...t,headers:l([{"anthropic-beta":[...i??[],"mcp-tunnels-2026-06-22"].toString(),...o!=null?{"anthropic-workspace-id":o}:void 0},t?.headers])})}list(s,e={},t){let{betas:r,workspace_id:i,...o}=e??{};return this._client.getAPIList(d`/v1/tunnels/${s}/certificates?beta=true`,S,{query:o,...t,headers:l([{"anthropic-beta":[...r??[],"mcp-tunnels-2026-06-22"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}archive(s,e,t){let{tunnel_id:r,betas:i,workspace_id:o}=e;return this._client.post(d`/v1/tunnels/${r}/certificates/${s}/archive?beta=true`,{...t,headers:l([{"anthropic-beta":[...i??[],"mcp-tunnels-2026-06-22"].toString(),...o!=null?{"anthropic-workspace-id":o}:void 0},t?.headers])})}};var ms=(()=>{class n extends w{constructor(){super(...arguments),this.certificates=new zt(this._client)}create(e,t){let{betas:r,workspace_id:i,...o}=e;return this._client.post("/v1/tunnels?beta=true",{body:o,...t,headers:l([{"anthropic-beta":[...r??[],"mcp-tunnels-2026-06-22"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}retrieve(e,t={},r){let{betas:i,workspace_id:o}=t??{};return this._client.get(d`/v1/tunnels/${e}?beta=true`,{...r,headers:l([{"anthropic-beta":[...i??[],"mcp-tunnels-2026-06-22"].toString(),...o!=null?{"anthropic-workspace-id":o}:void 0},r?.headers])})}list(e={},t){let{betas:r,workspace_id:i,...o}=e??{};return this._client.getAPIList("/v1/tunnels?beta=true",S,{query:o,...t,headers:l([{"anthropic-beta":[...r??[],"mcp-tunnels-2026-06-22"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}archive(e,t={},r){let{betas:i,workspace_id:o}=t??{};return this._client.post(d`/v1/tunnels/${e}/archive?beta=true`,{...r,headers:l([{"anthropic-beta":[...i??[],"mcp-tunnels-2026-06-22"].toString(),...o!=null?{"anthropic-workspace-id":o}:void 0},r?.headers])})}revealToken(e,t={},r){let{betas:i,workspace_id:o}=t??{};return this._client.post(d`/v1/tunnels/${e}/reveal_token?beta=true`,{...r,headers:l([{"anthropic-beta":[...i??[],"mcp-tunnels-2026-06-22"].toString(),...o!=null?{"anthropic-workspace-id":o}:void 0},r?.headers])})}rotateToken(e,t,r){let{betas:i,workspace_id:o,...c}=t;return this._client.post(d`/v1/tunnels/${e}/rotate_token?beta=true`,{body:c,...r,headers:l([{"anthropic-beta":[...i??[],"mcp-tunnels-2026-06-22"].toString(),...o!=null?{"anthropic-workspace-id":o}:void 0},r?.headers])})}}return n.Certificates=zt,n})();var Kt=class extends w{create(s,e,t){let{betas:r,workspace_id:i,...o}=e;return this._client.post(d`/v1/vaults/${s}/credentials?beta=true`,{body:o,...t,headers:l([{"anthropic-beta":[...r??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}retrieve(s,e,t){let{vault_id:r,betas:i,workspace_id:o}=e;return this._client.get(d`/v1/vaults/${r}/credentials/${s}?beta=true`,{...t,headers:l([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...o!=null?{"anthropic-workspace-id":o}:void 0},t?.headers])})}update(s,e,t){let{vault_id:r,betas:i,workspace_id:o,...c}=e;return this._client.post(d`/v1/vaults/${r}/credentials/${s}?beta=true`,{body:c,...t,headers:l([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...o!=null?{"anthropic-workspace-id":o}:void 0},t?.headers])})}list(s,e={},t){let{betas:r,workspace_id:i,...o}=e??{};return this._client.getAPIList(d`/v1/vaults/${s}/credentials?beta=true`,S,{query:o,...t,headers:l([{"anthropic-beta":[...r??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}delete(s,e,t){let{vault_id:r,betas:i,workspace_id:o}=e;return this._client.delete(d`/v1/vaults/${r}/credentials/${s}?beta=true`,{...t,headers:l([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...o!=null?{"anthropic-workspace-id":o}:void 0},t?.headers])})}archive(s,e,t){let{vault_id:r,betas:i,workspace_id:o}=e;return this._client.post(d`/v1/vaults/${r}/credentials/${s}/archive?beta=true`,{...t,headers:l([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...o!=null?{"anthropic-workspace-id":o}:void 0},t?.headers])})}mcpOAuthValidate(s,e,t){let{vault_id:r,betas:i,workspace_id:o}=e;return this._client.post(d`/v1/vaults/${r}/credentials/${s}/mcp_oauth_validate?beta=true`,{...t,headers:l([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...o!=null?{"anthropic-workspace-id":o}:void 0},t?.headers])})}};var _s=(()=>{class n extends w{constructor(){super(...arguments),this.credentials=new Kt(this._client)}create(e,t){let{betas:r,workspace_id:i,...o}=e;return this._client.post("/v1/vaults?beta=true",{body:o,...t,headers:l([{"anthropic-beta":[...r??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}retrieve(e,t={},r){let{betas:i,workspace_id:o}=t??{};return this._client.get(d`/v1/vaults/${e}?beta=true`,{...r,headers:l([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...o!=null?{"anthropic-workspace-id":o}:void 0},r?.headers])})}update(e,t,r){let{betas:i,workspace_id:o,...c}=t;return this._client.post(d`/v1/vaults/${e}?beta=true`,{body:c,...r,headers:l([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...o!=null?{"anthropic-workspace-id":o}:void 0},r?.headers])})}list(e={},t){let{betas:r,workspace_id:i,...o}=e??{};return this._client.getAPIList("/v1/vaults?beta=true",S,{query:o,...t,headers:l([{"anthropic-beta":[...r??[],"managed-agents-2026-04-01"].toString(),...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}delete(e,t={},r){let{betas:i,workspace_id:o}=t??{};return this._client.delete(d`/v1/vaults/${e}?beta=true`,{...r,headers:l([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...o!=null?{"anthropic-workspace-id":o}:void 0},r?.headers])})}archive(e,t={},r){let{betas:i,workspace_id:o}=t??{};return this._client.post(d`/v1/vaults/${e}/archive?beta=true`,{...r,headers:l([{"anthropic-beta":[...i??[],"managed-agents-2026-04-01"].toString(),...o!=null?{"anthropic-workspace-id":o}:void 0},r?.headers])})}}return n.Credentials=Kt,n})();var Lr=(()=>{class n extends w{constructor(){super(...arguments),this.models=new it(this._client),this.messages=new is(this._client),this.agents=new kn(this._client),this.environments=new Dn(this._client),this.sessions=new fs(this._client),this.deployments=new et(this._client),this.deploymentRuns=new Ze(this._client),this.vaults=new _s(this._client),this.memoryStores=new Wn(this._client),this.files=new st(this._client),this.skills=new ps(this._client),this.webhooks=new ct(this._client),this.userProfiles=new ot(this._client),this.dreams=new tt(this._client),this.tunnels=new ms(this._client),this.organization=new us(this._client)}}return n.Models=it,n.Messages=is,n.Agents=kn,n.Environments=Dn,n.Sessions=fs,n.Deployments=et,n.DeploymentRuns=Ze,n.Vaults=_s,n.MemoryStores=Wn,n.Files=st,n.Skills=ps,n.Webhooks=ct,n.UserProfiles=ot,n.Dreams=tt,n.Tunnels=ms,n.Organization=us,n})();var Ke=class extends w{create(s,e){let{betas:t,workspace_id:r,...i}=s;return this._client.post("/v1/complete",{body:i,timeout:this._client._options.timeout??6e5,...e,headers:l([{...t?.toString()!=null?{"anthropic-beta":t?.toString()}:void 0,...r!=null?{"anthropic-workspace-id":r}:void 0},e?.headers]),stream:s.stream??!1})}};var Ve=class extends w{list(s={},e){let{workspace_id:t,...r}=s??{};return this._client.getAPIList("/v1/files",S,{query:r,...e,headers:l([{...t!=null?{"anthropic-workspace-id":t}:void 0},e?.headers])})}delete(s,e={},t){let{workspace_id:r}=e??{};return this._client.delete(d`/v1/files/${s}`,{...t,headers:l([{...r!=null?{"anthropic-workspace-id":r}:void 0},t?.headers])})}download(s,e={},t){let{workspace_id:r}=e??{};return this._client.get(d`/v1/files/${s}/content`,{...t,headers:l([{Accept:"application/binary",...r!=null?{"anthropic-workspace-id":r}:void 0},t?.headers]),__binaryResponse:!0})}retrieveMetadata(s,e={},t){let{workspace_id:r}=e??{};return this._client.get(d`/v1/files/${s}`,{...t,headers:l([{...r!=null?{"anthropic-workspace-id":r}:void 0},t?.headers])})}upload(s,e){let{workspace_id:t,...r}=s;return this._client.post("/v1/files",ie({body:r,...e,headers:l([{...t!=null?{"anthropic-workspace-id":t}:void 0},wn(r.file),e?.headers])},this._client))}};function Sa(n){return n?.output_config?.format}function vi(n,s,e){let t=Sa(s);return!s||!("parse"in(t??{}))?{...n,content:n.content.map(r=>r.type==="text"?Object.defineProperty({...r},"parsed_output",{value:null,enumerable:!1}):r),parsed_output:null}:Ai(n,s,e)}function Ai(n,s,e){let t=null,r=n.content.map(i=>{if(i.type==="text"){let o=Jl(s,i.text);return t===null&&(t=o),Object.defineProperty({...i},"parsed_output",{value:o,enumerable:!1})}return i});return{...n,content:r,parsed_output:t}}function Jl(n,s){let e=Sa(n);if(e?.type!=="json_schema")return null;try{return"parse"in e?e.parse(s):JSON.parse(s)}catch(t){throw new y(`Failed to parse structured output: ${t}`)}}var ce,Ce,Vt,Fr,gs,Br,Hr,ws,Dr,ye,Wr,bs,ys,Je,ks,Ss,xs,jr,Ri,xa,Ei,Pi,Ii,Ti,va;function Mi(n){return n.type==="tool_use"||n.type==="server_tool_use"}var Aa=(()=>{class n{constructor(e,t){ce.add(this),this.messages=[],this.receivedMessages=[],Ce.set(this,void 0),Vt.set(this,null),this.controller=new AbortController,Fr.set(this,void 0),gs.set(this,()=>{}),Br.set(this,()=>{}),Hr.set(this,void 0),ws.set(this,()=>{}),Dr.set(this,()=>{}),ye.set(this,{}),Wr.set(this,!1),bs.set(this,!1),ys.set(this,!1),Je.set(this,!1),ks.set(this,void 0),Ss.set(this,void 0),xs.set(this,void 0),jr.set(this,void 0),Ei.set(this,r=>{if(f(this,bs,!0,"f"),le(r)&&(r=new K),r instanceof K)return f(this,ys,!0,"f"),this._emit("abort",r);if(r instanceof y)return this._emit("error",r);if(r instanceof Error){let i=new y(r.message);return i.cause=r,this._emit("error",i)}return this._emit("error",new y(String(r)))}),f(this,Fr,new Promise((r,i)=>{f(this,gs,r,"f"),f(this,Br,i,"f")}),"f"),f(this,Hr,new Promise((r,i)=>{f(this,ws,r,"f"),f(this,Dr,i,"f")}),"f"),a(this,Fr,"f").catch(()=>{}),a(this,Hr,"f").catch(()=>{}),f(this,Vt,e,"f"),f(this,jr,t?.logger??console,"f")}get response(){return a(this,ks,"f")}get request_id(){return a(this,Ss,"f")}get workspace_id(){return a(this,xs,"f")}async withResponse(){f(this,Je,!0,"f");let e=await a(this,Fr,"f");if(!e)throw new Error("Could not resolve a `Response` object");return{data:this,response:e,request_id:e.headers.get("request-id"),workspace_id:e.headers.get("anthropic-workspace-id")}}static fromReadableStream(e){let t=new n(null);return t._run(()=>t._fromReadableStream(e)),t}static createMessage(e,t,r,{logger:i}={}){let o=new n(t,{logger:i});for(let c of t.messages)o._addMessageParam(c);return f(o,Vt,{...t,stream:!0},"f"),o._run(()=>o._createMessage(e,{...t,stream:!0},{...r,headers:{...r?.headers,[nt]:"stream"}})),o}_run(e){e().then(()=>{this._emitFinal(),this._emit("end")},a(this,Ei,"f"))}_addMessageParam(e){this.messages.push(e)}_addMessage(e,t=!0){this.receivedMessages.push(e),t&&this._emit("message",e)}async _createMessage(e,t,r){let i=r?.signal,o;i&&(i.aborted&&this.controller.abort(),o=this.controller.abort.bind(this.controller),i.addEventListener("abort",o));try{a(this,ce,"m",Pi).call(this);let{response:c,data:h}=await e.create({...t,stream:!0},{...r,signal:this.controller.signal}).withResponse();this._connected(c);for await(let u of h)a(this,ce,"m",Ii).call(this,u);if(h.controller.signal?.aborted)throw new K;a(this,ce,"m",Ti).call(this)}finally{i&&o&&i.removeEventListener("abort",o)}}_connected(e){this.ended||(f(this,ks,e,"f"),f(this,Ss,e?.headers.get("request-id"),"f"),f(this,xs,e?.headers.get("anthropic-workspace-id"),"f"),a(this,gs,"f").call(this,e),this._emit("connect"))}get ended(){return a(this,Wr,"f")}get errored(){return a(this,bs,"f")}get aborted(){return a(this,ys,"f")}abort(){this.controller.abort()}on(e,t){return(a(this,ye,"f")[e]||(a(this,ye,"f")[e]=[])).push({listener:t}),this}off(e,t){let r=a(this,ye,"f")[e];if(!r)return this;let i=r.findIndex(o=>o.listener===t);return i>=0&&r.splice(i,1),this}once(e,t){return(a(this,ye,"f")[e]||(a(this,ye,"f")[e]=[])).push({listener:t,once:!0}),this}emitted(e){return new Promise((t,r)=>{f(this,Je,!0,"f"),e!=="error"&&this.once("error",r),this.once(e,t)})}async done(){f(this,Je,!0,"f"),await a(this,Hr,"f")}get currentMessage(){return a(this,Ce,"f")}async finalMessage(){return await this.done(),a(this,ce,"m",Ri).call(this)}async finalText(){return await this.done(),a(this,ce,"m",xa).call(this)}_emit(e,...t){if(a(this,Wr,"f"))return;e==="end"&&(f(this,Wr,!0,"f"),a(this,ws,"f").call(this));let r=a(this,ye,"f")[e];if(r&&(a(this,ye,"f")[e]=r.filter(i=>!i.once),r.forEach(({listener:i})=>i(...t))),e==="abort"){let i=t[0];!a(this,Je,"f")&&!r?.length&&Promise.reject(i),a(this,Br,"f").call(this,i),a(this,Dr,"f").call(this,i),this._emit("end");return}if(e==="error"){let i=t[0];!a(this,Je,"f")&&!r?.length&&Promise.reject(i),a(this,Br,"f").call(this,i),a(this,Dr,"f").call(this,i),this._emit("end")}}_emitFinal(){this.receivedMessages.at(-1)&&this._emit("finalMessage",a(this,ce,"m",Ri).call(this))}async _fromReadableStream(e,t){let r=t?.signal,i;r&&(r.aborted&&this.controller.abort(),i=this.controller.abort.bind(this.controller),r.addEventListener("abort",i));try{a(this,ce,"m",Pi).call(this),this._connected(null);let o=_e.fromReadableStream(e,this.controller);for await(let c of o)a(this,ce,"m",Ii).call(this,c);if(o.controller.signal?.aborted)throw new K;a(this,ce,"m",Ti).call(this)}finally{r&&i&&r.removeEventListener("abort",i)}}[(Ce=new WeakMap,Vt=new WeakMap,Fr=new WeakMap,gs=new WeakMap,Br=new WeakMap,Hr=new WeakMap,ws=new WeakMap,Dr=new WeakMap,ye=new WeakMap,Wr=new WeakMap,bs=new WeakMap,ys=new WeakMap,Je=new WeakMap,ks=new WeakMap,Ss=new WeakMap,xs=new WeakMap,jr=new WeakMap,Ei=new WeakMap,ce=new WeakSet,Ri=function(){if(this.receivedMessages.length===0)throw new y("stream ended without producing a Message with role=assistant");return this.receivedMessages.at(-1)},xa=function(){if(this.receivedMessages.length===0)throw new y("stream ended without producing a Message with role=assistant");let t=this.receivedMessages.at(-1).content.filter(r=>r.type==="text").map(r=>r.text);if(t.length===0)throw new y("stream ended without producing a content block with type=text");return t.join(" ")},Pi=function(){this.ended||f(this,Ce,void 0,"f")},Ii=function(t){if(this.ended)return;let r=a(this,ce,"m",va).call(this,t);switch(this._emit("streamEvent",t,r),t.type){case"content_block_delta":{let i=r.content.at(-1);switch(t.delta.type){case"text_delta":{i.type==="text"&&this._emit("text",t.delta.text,i.text||"");break}case"citations_delta":{i.type==="text"&&this._emit("citation",t.delta.citation,i.citations??[]);break}case"input_json_delta":{Mi(i)&&a(this,ye,"f").inputJson?.length&&this._emit("inputJson",t.delta.partial_json,i.input);break}case"thinking_delta":{i.type==="thinking"&&this._emit("thinking",t.delta.thinking,i.thinking);break}case"signature_delta":{i.type==="thinking"&&this._emit("signature",i.signature);break}default:t.delta}break}case"message_stop":{this._addMessageParam(r),this._addMessage(vi(r,a(this,Vt,"f"),{logger:a(this,jr,"f")}),!0);break}case"content_block_stop":{this._emit("contentBlock",r.content.at(-1));break}case"message_start":{f(this,Ce,r,"f");break}case"content_block_start":case"message_delta":break}},Ti=function(){if(this.ended)throw new y("stream has ended, this shouldn't happen");let t=a(this,Ce,"f");if(!t)throw new y("request ended without sending any chunks");return f(this,Ce,void 0,"f"),vi(t,a(this,Vt,"f"),{logger:a(this,jr,"f")})},va=function(t){let r=a(this,Ce,"f");if(t.type==="message_start"){if(r)throw new y(`Unexpected event order, got ${t.type} before receiving "message_stop"`);return t.message}if(!r)throw new y(`Unexpected event order, got ${t.type} before "message_start"`);switch(t.type){case"message_stop":return r;case"message_delta":return r.stop_reason=t.delta.stop_reason,r.stop_sequence=t.delta.stop_sequence,r.stop_details=t.delta.stop_details,r.usage.output_tokens=t.usage.output_tokens,t.delta.container!=null&&(r.container=t.delta.container),t.usage.input_tokens!=null&&(r.usage.input_tokens=t.usage.input_tokens),t.usage.cache_creation_input_tokens!=null&&(r.usage.cache_creation_input_tokens=t.usage.cache_creation_input_tokens),t.usage.cache_read_input_tokens!=null&&(r.usage.cache_read_input_tokens=t.usage.cache_read_input_tokens),t.usage.server_tool_use!=null&&(r.usage.server_tool_use=t.usage.server_tool_use),t.usage.output_tokens_details!=null&&(r.usage.output_tokens_details=t.usage.output_tokens_details),r;case"content_block_start":return r.content.push({...t.content_block}),r;case"content_block_delta":{let i=r.content.at(t.index);switch(t.delta.type){case"text_delta":{i?.type==="text"&&(r.content[t.index]={...i,text:(i.text||"")+t.delta.text});break}case"citations_delta":{i?.type==="text"&&(r.content[t.index]={...i,citations:[...i.citations??[],t.delta.citation]});break}case"input_json_delta":{if(i&&Mi(i)){let o=(i[Ie]||"")+t.delta.partial_json;r.content[t.index]=Un(i,o)}break}case"thinking_delta":{i?.type==="thinking"&&(r.content[t.index]={...i,thinking:i.thinking+t.delta.thinking});break}case"signature_delta":{i?.type==="thinking"&&(r.content[t.index]={...i,signature:t.delta.signature});break}default:t.delta}return r}case"content_block_stop":{let i=r.content.at(t.index);return i&&Mi(i)&&Ie in i&&Object.defineProperty(i,"input",{value:i.input,enumerable:!0,configurable:!0,writable:!0}),r}}},Symbol.asyncIterator)](){let e=[],t=[],r=!1;return this.on("streamEvent",i=>{let o=t.shift();o?o.resolve(i):e.push(i)}),this.on("end",()=>{r=!0;for(let i of t)i.resolve(void 0);t.length=0}),this.on("abort",i=>{r=!0;for(let o of t)o.reject(i);t.length=0}),this.on("error",i=>{r=!0;for(let o of t)o.reject(i);t.length=0}),{next:async()=>e.length?{value:e.shift(),done:!1}:r?{value:void 0,done:!0}:new Promise((o,c)=>t.push({resolve:o,reject:c})).then(o=>o?{value:o,done:!1}:{value:void 0,done:!0}),return:async()=>(this.abort(),{value:void 0,done:!0})}}toReadableStream(){return new _e(this[Symbol.asyncIterator].bind(this),this.controller).toReadableStream()}}return n})();var Jt=class extends w{create(s,e){let{user_profile_id:t,workspace_id:r,...i}=s;return this._client.post("/v1/messages/batches",{body:i,...e,headers:l([{...t!=null?{"anthropic-user-profile-id":t}:void 0,...r!=null?{"anthropic-workspace-id":r}:void 0},e?.headers])})}retrieve(s,e={},t){let{workspace_id:r}=e??{};return this._client.get(d`/v1/messages/batches/${s}`,{...t,headers:l([{...r!=null?{"anthropic-workspace-id":r}:void 0},t?.headers])})}list(s={},e){let{workspace_id:t,...r}=s??{};return this._client.getAPIList("/v1/messages/batches",W,{query:r,...e,headers:l([{...t!=null?{"anthropic-workspace-id":t}:void 0},e?.headers])})}delete(s,e={},t){let{workspace_id:r}=e??{};return this._client.delete(d`/v1/messages/batches/${s}`,{...t,headers:l([{...r!=null?{"anthropic-workspace-id":r}:void 0},t?.headers])})}cancel(s,e={},t){let{workspace_id:r}=e??{};return this._client.post(d`/v1/messages/batches/${s}/cancel`,{...t,headers:l([{...r!=null?{"anthropic-workspace-id":r}:void 0},t?.headers])})}async results(s,e={},t){let r=await this.retrieve(s,e,t);if(!r.results_url)throw new y(`No batch \`results_url\`; Has it finished processing? ${r.processing_status} - ${r.id}`);let{workspace_id:i}=e??{};return this._client.get(r.results_url,{...t,headers:l([{Accept:"application/binary",...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers]),stream:!0,__binaryResponse:!0})._thenUnwrap((o,c)=>jn.fromResponse(c.response,c.controller))}};var qr=(()=>{class n extends w{constructor(){super(...arguments),this.batches=new Jt(this._client)}create(e,t){let{user_profile_id:r,workspace_id:i,...o}=e;o.model in Ra&&console.warn(`The model '${o.model}' is deprecated and will reach end-of-life on ${Ra[o.model]}
|
|
14
14
|
Please migrate to a newer model. Visit https://docs.anthropic.com/en/docs/resources/model-deprecations for more information.`),Gl.includes(o.model)&&o.thinking&&o.thinking.type==="enabled"&&console.warn(`Using Claude with ${o.model} and 'thinking.type=enabled' is deprecated. Use 'thinking.type=adaptive' instead which results in better model performance in our testing: https://platform.claude.com/docs/en/build-with-claude/adaptive-thinking`);let c=t?.timeout??this._client._options.timeout;if(!o.stream&&c==null){let u=qn[o.model]??void 0;c=this._client.calculateNonstreamingTimeout(o.max_tokens,u)}let h=gn(o.tools,o.messages);return this._client.post("/v1/messages",{body:o,timeout:c??6e5,...t,headers:l([{...r!=null?{"anthropic-user-profile-id":r}:void 0,...i!=null?{"anthropic-workspace-id":i}:void 0},h,t?.headers]),stream:e.stream??!1})}parse(e,t){return this.create(e,t).then(r=>Ai(r,e,{logger:this._client.logger??console}))}stream(e,t){return Aa.createMessage(this,e,t,{logger:this._client.logger??console})}countTokens(e,t){let{user_profile_id:r,workspace_id:i,...o}=e;return this._client.post("/v1/messages/count_tokens",{body:o,...t,headers:l([{...r!=null?{"anthropic-user-profile-id":r}:void 0,...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}}return n.Batches=Jt,n})(),Ra={},Gl=["claude-mythos-preview","claude-opus-4-6"];var Xe=class extends w{retrieve(s,e={},t){let{betas:r,workspace_id:i}=e??{};return this._client.get(d`/v1/models/${s}`,{...t,headers:l([{...r?.toString()!=null?{"anthropic-beta":r?.toString()}:void 0,...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}list(s={},e){let{betas:t,workspace_id:r,...i}=s??{};return this._client.getAPIList("/v1/models",W,{query:i,...e,headers:l([{...t?.toString()!=null?{"anthropic-beta":t?.toString()}:void 0,...r!=null?{"anthropic-workspace-id":r}:void 0},e?.headers])})}};var Xt=class extends w{create(s,e,t){let{workspace_id:r,...i}=e;return this._client.post(d`/v1/skills/${s}/versions`,ie({body:i,...t,headers:l([{...r!=null?{"anthropic-workspace-id":r}:void 0},t?.headers])},this._client,!1))}retrieve(s,e,t){let{skill_id:r,workspace_id:i}=e;return this._client.get(d`/v1/skills/${r}/versions/${s}`,{...t,headers:l([{...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}list(s,e={},t){let{workspace_id:r,...i}=e??{};return this._client.getAPIList(d`/v1/skills/${s}/versions`,S,{query:i,...t,headers:l([{...r!=null?{"anthropic-workspace-id":r}:void 0},t?.headers])})}delete(s,e,t){let{skill_id:r,workspace_id:i}=e;return this._client.delete(d`/v1/skills/${r}/versions/${s}`,{...t,headers:l([{...i!=null?{"anthropic-workspace-id":i}:void 0},t?.headers])})}};var Ur=(()=>{class n extends w{constructor(){super(...arguments),this.versions=new Xt(this._client)}create(e,t){let{workspace_id:r,...i}=e;return this._client.post("/v1/skills",ie({body:i,...t,headers:l([{...r!=null?{"anthropic-workspace-id":r}:void 0},t?.headers])},this._client,!1))}retrieve(e,t={},r){let{workspace_id:i}=t??{};return this._client.get(d`/v1/skills/${e}`,{...r,headers:l([{...i!=null?{"anthropic-workspace-id":i}:void 0},r?.headers])})}list(e={},t){let{workspace_id:r,...i}=e??{};return this._client.getAPIList("/v1/skills",S,{query:i,...t,headers:l([{...r!=null?{"anthropic-workspace-id":r}:void 0},t?.headers])})}delete(e,t={},r){let{workspace_id:i}=t??{};return this._client.delete(d`/v1/skills/${e}`,{...r,headers:l([{...i!=null?{"anthropic-workspace-id":i}:void 0},r?.headers])})}}return n.Versions=Xt,n})();var Oi,Ci,vs,Ea,Zl="\\n\\nHuman:",eu="\\n\\nAssistant:",tu=(()=>{class n{get credentials(){return this._authState.provider}constructor({baseURL:e=P("ANTHROPIC_BASE_URL"),apiKey:t,authToken:r,webhookKey:i=P("ANTHROPIC_WEBHOOK_SIGNING_KEY")??null,...o}={}){if(Oi.add(this),this._requestAuthFlags=new WeakMap,vs.set(this,void 0),t===void 0&&(t=o.profile!=null?null:P("ANTHROPIC_API_KEY")??null),r===void 0&&(r=o.profile!=null?null:P("ANTHROPIC_AUTH_TOKEN")??null),o.profile!=null&&(o.credentials!=null||o.config!=null))throw new TypeError("Pass at most one of `profile`, `credentials`, or `config`.");let c={apiKey:t,authToken:r,webhookKey:i,...o,baseURL:e||"https://api.anthropic.com"};if(!c.dangerouslyAllowBrowser&&ji())throw new y(`It looks like you're running in a browser-like environment.
|
|
15
15
|
|