@anthropic-ai/sdk 0.125.0 → 0.127.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +88 -0
- package/client.d.mts +12 -11
- package/client.d.mts.map +1 -1
- package/client.d.ts +12 -11
- package/client.d.ts.map +1 -1
- package/client.js +865 -845
- package/client.js.map +1 -1
- package/client.mjs +866 -840
- package/client.mjs.map +1 -1
- package/core/api-promise.js +71 -68
- package/core/api-promise.js.map +1 -1
- package/core/api-promise.mjs +71 -64
- package/core/api-promise.mjs.map +1 -1
- package/core/error.js +5 -2
- package/core/error.js.map +1 -1
- package/core/error.mjs +5 -2
- package/core/error.mjs.map +1 -1
- package/core/pagination.js +56 -50
- package/core/pagination.js.map +1 -1
- package/core/pagination.mjs +56 -41
- package/core/pagination.mjs.map +1 -1
- package/core/streaming.js +212 -209
- package/core/streaming.js.map +1 -1
- package/core/streaming.mjs +212 -209
- package/core/streaming.mjs.map +1 -1
- package/helpers/beta/mcp.js +14 -19
- package/helpers/beta/mcp.js.map +1 -1
- package/helpers/beta/mcp.mjs +14 -13
- package/helpers/beta/mcp.mjs.map +1 -1
- package/internal/constants.js +1 -1
- package/internal/constants.js.map +1 -1
- package/internal/decoders/jsonl.js +27 -24
- package/internal/decoders/jsonl.js.map +1 -1
- package/internal/decoders/jsonl.mjs +27 -24
- package/internal/decoders/jsonl.mjs.map +1 -1
- package/internal/decoders/line.js +52 -49
- package/internal/decoders/line.js.map +1 -1
- package/internal/decoders/line.mjs +52 -43
- package/internal/decoders/line.mjs.map +1 -1
- package/internal/file-store.js +256 -258
- package/internal/file-store.js.map +1 -1
- package/internal/file-store.mjs +256 -243
- package/internal/file-store.mjs.map +1 -1
- package/internal/node.browser.d.mts.map +1 -1
- package/internal/node.browser.d.ts.map +1 -1
- package/internal/node.browser.js.map +1 -1
- package/internal/node.browser.mjs +7 -7
- package/internal/node.browser.mjs.map +1 -1
- package/internal/parse.d.mts.map +1 -1
- package/internal/parse.d.ts.map +1 -1
- package/internal/parse.js +2 -2
- package/internal/parse.js.map +1 -1
- package/internal/parse.mjs +3 -3
- package/internal/parse.mjs.map +1 -1
- package/internal/shim-types.js +0 -6
- package/internal/shim-types.js.map +1 -1
- package/internal/shim-types.mjs +0 -6
- package/internal/shim-types.mjs.map +1 -1
- package/internal/shims.d.mts +3 -3
- package/internal/shims.d.mts.map +1 -1
- package/internal/shims.d.ts +3 -3
- package/internal/shims.d.ts.map +1 -1
- package/internal/shims.js +0 -6
- package/internal/shims.js.map +1 -1
- package/internal/shims.mjs +0 -6
- package/internal/shims.mjs.map +1 -1
- package/internal/stainless-helper-header.js +6 -6
- package/internal/stainless-helper-header.js.map +1 -1
- package/internal/utils/async-queue.js +66 -63
- package/internal/utils/async-queue.js.map +1 -1
- package/internal/utils/async-queue.mjs +66 -56
- package/internal/utils/async-queue.mjs.map +1 -1
- package/internal/utils/bytes.d.mts +1 -1
- package/internal/utils/bytes.d.mts.map +1 -1
- package/internal/utils/bytes.d.ts +1 -1
- package/internal/utils/bytes.d.ts.map +1 -1
- package/internal/utils/log.d.mts +7 -12
- package/internal/utils/log.d.mts.map +1 -1
- package/internal/utils/log.d.ts +7 -12
- package/internal/utils/log.d.ts.map +1 -1
- package/internal/utils/log.js +12 -0
- package/internal/utils/log.js.map +1 -1
- package/internal/utils/log.mjs +11 -0
- package/internal/utils/log.mjs.map +1 -1
- package/lib/BetaMessageStream.d.mts.map +1 -1
- package/lib/BetaMessageStream.d.ts.map +1 -1
- package/lib/BetaMessageStream.js +595 -590
- package/lib/BetaMessageStream.js.map +1 -1
- package/lib/BetaMessageStream.mjs +595 -590
- package/lib/BetaMessageStream.mjs.map +1 -1
- package/lib/MessageStream.js +544 -541
- package/lib/MessageStream.js.map +1 -1
- package/lib/MessageStream.mjs +544 -541
- package/lib/MessageStream.mjs.map +1 -1
- package/lib/beta-parser.d.mts +1 -3
- package/lib/beta-parser.d.mts.map +1 -1
- package/lib/beta-parser.d.ts +1 -3
- package/lib/beta-parser.d.ts.map +1 -1
- package/lib/beta-parser.js.map +1 -1
- package/lib/beta-parser.mjs.map +1 -1
- package/lib/environments/poller.js +180 -174
- package/lib/environments/poller.js.map +1 -1
- package/lib/environments/poller.mjs +180 -153
- package/lib/environments/poller.mjs.map +1 -1
- package/lib/environments/worker.js +375 -369
- package/lib/environments/worker.js.map +1 -1
- package/lib/environments/worker.mjs +374 -329
- package/lib/environments/worker.mjs.map +1 -1
- package/lib/internal/stub.d.mts +2 -0
- package/lib/internal/stub.d.mts.map +1 -0
- package/lib/internal/stub.d.ts +2 -0
- package/lib/internal/stub.d.ts.map +1 -0
- package/lib/internal/stub.js +6 -0
- package/lib/internal/stub.js.map +1 -0
- package/lib/internal/stub.mjs +3 -0
- package/lib/internal/stub.mjs.map +1 -0
- package/lib/internal/types.d.mts +5 -0
- package/lib/internal/types.d.mts.map +1 -0
- package/lib/internal/types.d.ts +5 -0
- package/lib/internal/types.d.ts.map +1 -0
- package/lib/internal/types.js +3 -0
- package/lib/internal/types.js.map +1 -0
- package/lib/internal/types.mjs +2 -0
- package/lib/internal/types.mjs.map +1 -0
- package/lib/middleware.js +6 -1
- package/lib/middleware.js.map +1 -1
- package/lib/middleware.mjs +6 -1
- package/lib/middleware.mjs.map +1 -1
- package/lib/parser.d.mts +1 -3
- package/lib/parser.d.mts.map +1 -1
- package/lib/parser.d.ts +1 -3
- package/lib/parser.d.ts.map +1 -1
- package/lib/parser.js.map +1 -1
- package/lib/parser.mjs.map +1 -1
- package/lib/tools/BetaToolRunner.d.mts +21 -6
- package/lib/tools/BetaToolRunner.d.mts.map +1 -1
- package/lib/tools/BetaToolRunner.d.ts +21 -6
- package/lib/tools/BetaToolRunner.d.ts.map +1 -1
- package/lib/tools/BetaToolRunner.js +415 -310
- package/lib/tools/BetaToolRunner.js.map +1 -1
- package/lib/tools/BetaToolRunner.mjs +414 -303
- package/lib/tools/BetaToolRunner.mjs.map +1 -1
- package/lib/tools/SessionToolRunner.js +241 -235
- package/lib/tools/SessionToolRunner.js.map +1 -1
- package/lib/tools/SessionToolRunner.mjs +241 -192
- package/lib/tools/SessionToolRunner.mjs.map +1 -1
- package/lib/tools/ToolError.js +39 -36
- package/lib/tools/ToolError.js.map +1 -1
- package/lib/tools/ToolError.mjs +39 -13
- package/lib/tools/ToolError.mjs.map +1 -1
- package/lib/transform-json-schema.js +7 -5
- package/lib/transform-json-schema.js.map +1 -1
- package/lib/transform-json-schema.mjs +7 -5
- package/lib/transform-json-schema.mjs.map +1 -1
- package/package.json +4 -3
- package/resources/beta/agents/agents.js +135 -132
- package/resources/beta/agents/agents.js.map +1 -1
- package/resources/beta/agents/agents.mjs +135 -132
- package/resources/beta/agents/agents.mjs.map +1 -1
- package/resources/beta/beta.d.mts +5 -5
- package/resources/beta/beta.d.mts.map +1 -1
- package/resources/beta/beta.d.ts +5 -5
- package/resources/beta/beta.d.ts.map +1 -1
- package/resources/beta/beta.js +39 -36
- package/resources/beta/beta.js.map +1 -1
- package/resources/beta/beta.mjs +39 -36
- package/resources/beta/beta.mjs.map +1 -1
- package/resources/beta/deployment-runs.d.mts +4 -0
- package/resources/beta/deployment-runs.d.mts.map +1 -1
- package/resources/beta/deployment-runs.d.ts +4 -0
- package/resources/beta/deployment-runs.d.ts.map +1 -1
- package/resources/beta/deployments.d.mts +5 -0
- package/resources/beta/deployments.d.mts.map +1 -1
- package/resources/beta/deployments.d.ts +5 -0
- package/resources/beta/deployments.d.ts.map +1 -1
- package/resources/beta/dreams.d.mts +19 -28
- package/resources/beta/dreams.d.mts.map +1 -1
- package/resources/beta/dreams.d.ts +19 -28
- package/resources/beta/dreams.d.ts.map +1 -1
- package/resources/beta/environments/environments.js +157 -154
- package/resources/beta/environments/environments.js.map +1 -1
- package/resources/beta/environments/environments.mjs +157 -154
- package/resources/beta/environments/environments.mjs.map +1 -1
- package/resources/beta/environments/work.js +255 -252
- package/resources/beta/environments/work.js.map +1 -1
- package/resources/beta/environments/work.mjs +255 -252
- package/resources/beta/environments/work.mjs.map +1 -1
- package/resources/beta/index.d.mts +2 -2
- package/resources/beta/index.d.mts.map +1 -1
- package/resources/beta/index.d.ts +2 -2
- package/resources/beta/index.d.ts.map +1 -1
- package/resources/beta/index.js.map +1 -1
- package/resources/beta/index.mjs.map +1 -1
- package/resources/beta/memory-stores/memories.d.mts +6 -0
- package/resources/beta/memory-stores/memories.d.mts.map +1 -1
- package/resources/beta/memory-stores/memories.d.ts +6 -0
- package/resources/beta/memory-stores/memories.d.ts.map +1 -1
- package/resources/beta/memory-stores/memory-stores.js +150 -147
- package/resources/beta/memory-stores/memory-stores.js.map +1 -1
- package/resources/beta/memory-stores/memory-stores.mjs +150 -147
- package/resources/beta/memory-stores/memory-stores.mjs.map +1 -1
- package/resources/beta/memory-stores/memory-versions.d.mts +7 -0
- package/resources/beta/memory-stores/memory-versions.d.mts.map +1 -1
- package/resources/beta/memory-stores/memory-versions.d.ts +7 -0
- package/resources/beta/memory-stores/memory-versions.d.ts.map +1 -1
- package/resources/beta/messages/batches.d.mts +12 -1
- package/resources/beta/messages/batches.d.mts.map +1 -1
- package/resources/beta/messages/batches.d.ts +12 -1
- package/resources/beta/messages/batches.d.ts.map +1 -1
- package/resources/beta/messages/index.d.mts +1 -1
- package/resources/beta/messages/index.d.mts.map +1 -1
- package/resources/beta/messages/index.d.ts +1 -1
- package/resources/beta/messages/index.d.ts.map +1 -1
- package/resources/beta/messages/index.js.map +1 -1
- package/resources/beta/messages/index.mjs.map +1 -1
- package/resources/beta/messages/messages.d.mts +239 -101
- package/resources/beta/messages/messages.d.mts.map +1 -1
- package/resources/beta/messages/messages.d.ts +239 -101
- package/resources/beta/messages/messages.d.ts.map +1 -1
- package/resources/beta/messages/messages.js +113 -110
- package/resources/beta/messages/messages.js.map +1 -1
- package/resources/beta/messages/messages.mjs +113 -110
- package/resources/beta/messages/messages.mjs.map +1 -1
- package/resources/beta/models.d.mts +22 -1
- package/resources/beta/models.d.mts.map +1 -1
- package/resources/beta/models.d.ts +22 -1
- package/resources/beta/models.d.ts.map +1 -1
- package/resources/beta/organization/federation/federation.js +11 -8
- package/resources/beta/organization/federation/federation.js.map +1 -1
- package/resources/beta/organization/federation/federation.mjs +11 -8
- package/resources/beta/organization/federation/federation.mjs.map +1 -1
- package/resources/beta/organization/federation/rules/rules.js +187 -184
- package/resources/beta/organization/federation/rules/rules.js.map +1 -1
- package/resources/beta/organization/federation/rules/rules.mjs +187 -184
- package/resources/beta/organization/federation/rules/rules.mjs.map +1 -1
- package/resources/beta/organization/index.d.mts +1 -1
- package/resources/beta/organization/index.d.mts.map +1 -1
- package/resources/beta/organization/index.d.ts +1 -1
- package/resources/beta/organization/index.d.ts.map +1 -1
- package/resources/beta/organization/index.js.map +1 -1
- package/resources/beta/organization/index.mjs.map +1 -1
- package/resources/beta/organization/organization.d.mts +2 -2
- package/resources/beta/organization/organization.d.mts.map +1 -1
- package/resources/beta/organization/organization.d.ts +2 -2
- package/resources/beta/organization/organization.d.ts.map +1 -1
- package/resources/beta/organization/organization.js +38 -35
- package/resources/beta/organization/organization.js.map +1 -1
- package/resources/beta/organization/organization.mjs +38 -35
- package/resources/beta/organization/organization.mjs.map +1 -1
- package/resources/beta/organization/rate-limits.d.mts +87 -5
- package/resources/beta/organization/rate-limits.d.mts.map +1 -1
- package/resources/beta/organization/rate-limits.d.ts +87 -5
- package/resources/beta/organization/rate-limits.d.ts.map +1 -1
- package/resources/beta/organization/service-accounts/service-accounts.js +163 -160
- package/resources/beta/organization/service-accounts/service-accounts.js.map +1 -1
- package/resources/beta/organization/service-accounts/service-accounts.mjs +163 -160
- package/resources/beta/organization/service-accounts/service-accounts.mjs.map +1 -1
- package/resources/beta/organization/workspaces/rate-limits.d.mts +9 -4
- package/resources/beta/organization/workspaces/rate-limits.d.mts.map +1 -1
- package/resources/beta/organization/workspaces/rate-limits.d.ts +9 -4
- package/resources/beta/organization/workspaces/rate-limits.d.ts.map +1 -1
- package/resources/beta/organization/workspaces/rate-limits.js.map +1 -1
- package/resources/beta/organization/workspaces/rate-limits.mjs.map +1 -1
- package/resources/beta/organization/workspaces/workspaces.d.mts +3 -3
- package/resources/beta/organization/workspaces/workspaces.d.mts.map +1 -1
- package/resources/beta/organization/workspaces/workspaces.d.ts +3 -3
- package/resources/beta/organization/workspaces/workspaces.d.ts.map +1 -1
- package/resources/beta/organization/workspaces/workspaces.js +97 -94
- package/resources/beta/organization/workspaces/workspaces.js.map +1 -1
- package/resources/beta/organization/workspaces/workspaces.mjs +97 -94
- package/resources/beta/organization/workspaces/workspaces.mjs.map +1 -1
- package/resources/beta/sessions/events.d.mts +12 -21
- package/resources/beta/sessions/events.d.mts.map +1 -1
- package/resources/beta/sessions/events.d.ts +12 -21
- package/resources/beta/sessions/events.d.ts.map +1 -1
- package/resources/beta/sessions/events.js +118 -115
- package/resources/beta/sessions/events.js.map +1 -1
- package/resources/beta/sessions/events.mjs +118 -115
- package/resources/beta/sessions/events.mjs.map +1 -1
- package/resources/beta/sessions/resources.d.mts +0 -3
- package/resources/beta/sessions/resources.d.mts.map +1 -1
- package/resources/beta/sessions/resources.d.ts +0 -3
- package/resources/beta/sessions/resources.d.ts.map +1 -1
- package/resources/beta/sessions/sessions.d.mts +8 -2
- package/resources/beta/sessions/sessions.d.mts.map +1 -1
- package/resources/beta/sessions/sessions.d.ts +8 -2
- package/resources/beta/sessions/sessions.d.ts.map +1 -1
- package/resources/beta/sessions/sessions.js +161 -158
- package/resources/beta/sessions/sessions.js.map +1 -1
- package/resources/beta/sessions/sessions.mjs +161 -158
- package/resources/beta/sessions/sessions.mjs.map +1 -1
- package/resources/beta/sessions/threads/threads.js +86 -83
- package/resources/beta/sessions/threads/threads.js.map +1 -1
- package/resources/beta/sessions/threads/threads.mjs +86 -83
- package/resources/beta/sessions/threads/threads.mjs.map +1 -1
- package/resources/beta/skills/skills.js +104 -101
- package/resources/beta/skills/skills.js.map +1 -1
- package/resources/beta/skills/skills.mjs +104 -101
- package/resources/beta/skills/skills.mjs.map +1 -1
- package/resources/beta/tunnels/certificates.d.mts +2 -2
- package/resources/beta/tunnels/certificates.d.ts +2 -2
- package/resources/beta/tunnels/tunnels.js +188 -185
- package/resources/beta/tunnels/tunnels.js.map +1 -1
- package/resources/beta/tunnels/tunnels.mjs +188 -185
- package/resources/beta/tunnels/tunnels.mjs.map +1 -1
- package/resources/beta/user-profiles.d.mts +45 -0
- package/resources/beta/user-profiles.d.mts.map +1 -1
- package/resources/beta/user-profiles.d.ts +45 -0
- package/resources/beta/user-profiles.d.ts.map +1 -1
- package/resources/beta/user-profiles.js +25 -10
- package/resources/beta/user-profiles.js.map +1 -1
- package/resources/beta/user-profiles.mjs +25 -10
- package/resources/beta/user-profiles.mjs.map +1 -1
- package/resources/beta/vaults/credentials.d.mts +19 -19
- package/resources/beta/vaults/credentials.d.mts.map +1 -1
- package/resources/beta/vaults/credentials.d.ts +19 -19
- package/resources/beta/vaults/credentials.d.ts.map +1 -1
- package/resources/beta/vaults/vaults.js +156 -153
- package/resources/beta/vaults/vaults.js.map +1 -1
- package/resources/beta/vaults/vaults.mjs +156 -153
- package/resources/beta/vaults/vaults.mjs.map +1 -1
- package/resources/completions.d.mts +1 -1
- package/resources/completions.d.ts +1 -1
- package/resources/index.d.mts +1 -1
- package/resources/index.d.mts.map +1 -1
- package/resources/index.d.ts +1 -1
- package/resources/index.d.ts.map +1 -1
- package/resources/index.js.map +1 -1
- package/resources/index.mjs.map +1 -1
- package/resources/messages/index.d.mts +1 -1
- package/resources/messages/index.d.mts.map +1 -1
- package/resources/messages/index.d.ts +1 -1
- package/resources/messages/index.d.ts.map +1 -1
- package/resources/messages/index.js.map +1 -1
- package/resources/messages/index.mjs.map +1 -1
- package/resources/messages/messages.d.mts +100 -63
- package/resources/messages/messages.d.mts.map +1 -1
- package/resources/messages/messages.d.ts +100 -63
- package/resources/messages/messages.d.ts.map +1 -1
- package/resources/messages/messages.js +115 -112
- package/resources/messages/messages.js.map +1 -1
- package/resources/messages/messages.mjs +115 -112
- package/resources/messages/messages.mjs.map +1 -1
- package/resources/skills/skills.js +88 -85
- package/resources/skills/skills.js.map +1 -1
- package/resources/skills/skills.mjs +88 -85
- package/resources/skills/skills.mjs.map +1 -1
- package/resources/top-level.js +0 -1
- package/resources/top-level.js.map +1 -1
- package/resources/top-level.mjs +0 -1
- package/resources/top-level.mjs.map +1 -1
- package/src/client.ts +95 -72
- package/src/internal/node.browser.ts +7 -7
- package/src/internal/parse.ts +8 -11
- package/src/internal/shims.ts +4 -3
- package/src/internal/utils/bytes.ts +1 -1
- package/src/internal/utils/log.ts +16 -2
- package/src/lib/BetaMessageStream.ts +7 -5
- package/src/lib/beta-parser.ts +1 -3
- package/src/lib/internal/stub.ts +2 -0
- package/src/lib/internal/types.ts +2 -0
- package/src/lib/middleware.ts +6 -1
- package/src/lib/parser.ts +1 -3
- package/src/lib/tools/BetaToolRunner.ts +157 -24
- package/src/lib/transform-json-schema.ts +8 -6
- package/src/resources/beta/beta.ts +24 -1
- package/src/resources/beta/deployment-runs.ts +4 -0
- package/src/resources/beta/deployments.ts +5 -0
- package/src/resources/beta/dreams.ts +19 -28
- package/src/resources/beta/index.ts +11 -0
- package/src/resources/beta/memory-stores/memories.ts +6 -0
- package/src/resources/beta/memory-stores/memory-versions.ts +7 -0
- package/src/resources/beta/messages/batches.ts +13 -1
- package/src/resources/beta/messages/index.ts +10 -0
- package/src/resources/beta/messages/messages.ts +289 -100
- package/src/resources/beta/models.ts +25 -0
- package/src/resources/beta/organization/index.ts +6 -0
- package/src/resources/beta/organization/organization.ts +12 -0
- package/src/resources/beta/organization/rate-limits.ts +112 -4
- package/src/resources/beta/organization/workspaces/rate-limits.ts +16 -4
- package/src/resources/beta/organization/workspaces/workspaces.ts +3 -3
- package/src/resources/beta/sessions/events.ts +12 -21
- package/src/resources/beta/sessions/resources.ts +0 -3
- package/src/resources/beta/sessions/sessions.ts +8 -2
- package/src/resources/beta/tunnels/certificates.ts +2 -2
- package/src/resources/beta/user-profiles.ts +75 -10
- package/src/resources/beta/vaults/credentials.ts +19 -19
- package/src/resources/completions.ts +1 -1
- package/src/resources/index.ts +6 -0
- package/src/resources/messages/index.ts +6 -0
- package/src/resources/messages/messages.ts +128 -62
- package/src/tsconfig.json +13 -3
- package/src/version.ts +1 -1
- package/tools/agent-toolset/fs-util.js +0 -6
- package/tools/agent-toolset/fs-util.js.map +1 -1
- package/tools/agent-toolset/fs-util.mjs +0 -6
- package/tools/agent-toolset/fs-util.mjs.map +1 -1
- package/tools/agent-toolset/memories.js +4 -4
- package/tools/agent-toolset/memories.js.map +1 -1
- package/tools/agent-toolset/memories.mjs +2 -2
- package/tools/agent-toolset/memories.mjs.map +1 -1
- package/tools/agent-toolset/node.browser.js +12 -12
- package/tools/agent-toolset/node.browser.js.map +1 -1
- package/tools/agent-toolset/node.js +142 -139
- package/tools/agent-toolset/node.js.map +1 -1
- package/tools/agent-toolset/node.mjs +132 -125
- package/tools/agent-toolset/node.mjs.map +1 -1
- package/tools/agent-toolset/skills.js +5 -5
- package/tools/agent-toolset/skills.js.map +1 -1
- package/tools/agent-toolset/sync-interval.js +3 -3
- package/tools/agent-toolset/sync-interval.js.map +1 -1
- package/tools/memory/node.browser.js +2 -2
- package/tools/memory/node.browser.js.map +1 -1
- package/version.d.mts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var _BetaToolRunner_instances, _BetaToolRunner_consumed, _BetaToolRunner_mutated, _BetaToolRunner_state, _BetaToolRunner_options, _BetaToolRunner_message, _BetaToolRunner_toolResponse, _BetaToolRunner_completion, _BetaToolRunner_iterationCount, _BetaToolRunner_checkAndCompact, _BetaToolRunner_generateToolResponse;
|
|
2
|
+
var _BetaToolRunner_instances, _BetaToolRunner_consumed, _BetaToolRunner_mutated, _BetaToolRunner_state, _BetaToolRunner_options, _BetaToolRunner_message, _BetaToolRunner_stream, _BetaToolRunner_toolResponse, _BetaToolRunner_completion, _BetaToolRunner_iterationCount, _BetaToolRunner_compaction, _BetaToolRunner_turnPaused, _BetaToolRunner_checkAndCompact, _BetaToolRunner_send, _BetaToolRunner_compact, _BetaToolRunner_compactAfterFinalTurn, _BetaToolRunner_generateToolResponse;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.BetaToolRunner = void 0;
|
|
5
5
|
const tslib_1 = require("../../internal/tslib.js");
|
|
@@ -8,352 +8,457 @@ const error_1 = require("../../core/error.js");
|
|
|
8
8
|
const headers_1 = require("../../internal/headers.js");
|
|
9
9
|
const promise_1 = require("../../internal/utils/promise.js");
|
|
10
10
|
const values_1 = require("../../internal/utils/values.js");
|
|
11
|
+
const log_1 = require("../../internal/utils/log.js");
|
|
11
12
|
const CompactionControl_1 = require("./CompactionControl.js");
|
|
12
13
|
const stainless_helper_header_1 = require("../../internal/stainless-helper-header.js");
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
if (tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_message, "f") !== undefined) {
|
|
73
|
-
try {
|
|
74
|
-
const message = await tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_message, "f");
|
|
75
|
-
const totalInputTokens = message.usage.input_tokens +
|
|
76
|
-
(message.usage.cache_creation_input_tokens ?? 0) +
|
|
77
|
-
(message.usage.cache_read_input_tokens ?? 0);
|
|
78
|
-
tokensUsed = totalInputTokens + message.usage.output_tokens;
|
|
14
|
+
var BetaToolRunner = /* @__PURE__ */ (() => {
|
|
15
|
+
/**
|
|
16
|
+
* A ToolRunner handles the automatic conversation loop between the assistant and tools.
|
|
17
|
+
*
|
|
18
|
+
* A ToolRunner is an async iterable that yields either BetaMessage or BetaMessageStream objects
|
|
19
|
+
* depending on the streaming configuration.
|
|
20
|
+
*/
|
|
21
|
+
class BetaToolRunner {
|
|
22
|
+
constructor(client, params, options) {
|
|
23
|
+
_BetaToolRunner_instances.add(this);
|
|
24
|
+
this.client = client;
|
|
25
|
+
/** Whether the async iterator has been consumed */
|
|
26
|
+
_BetaToolRunner_consumed.set(this, false);
|
|
27
|
+
/** Whether parameters have been mutated since the last API call */
|
|
28
|
+
_BetaToolRunner_mutated.set(this, false);
|
|
29
|
+
/** Current state containing the request parameters */
|
|
30
|
+
_BetaToolRunner_state.set(this, void 0);
|
|
31
|
+
_BetaToolRunner_options.set(this, void 0);
|
|
32
|
+
/** Promise for the last message received from the assistant */
|
|
33
|
+
_BetaToolRunner_message.set(this, void 0);
|
|
34
|
+
/** The stream of the request in progress, when streaming */
|
|
35
|
+
_BetaToolRunner_stream.set(this, void 0);
|
|
36
|
+
/** Cached tool response to avoid redundant executions */
|
|
37
|
+
_BetaToolRunner_toolResponse.set(this, void 0);
|
|
38
|
+
/** Promise resolvers for waiting on completion */
|
|
39
|
+
_BetaToolRunner_completion.set(this, void 0);
|
|
40
|
+
/** Number of iterations (API requests) made so far */
|
|
41
|
+
_BetaToolRunner_iterationCount.set(this, 0);
|
|
42
|
+
/** A compaction scheduled with `compactBeforeNextTurn()`, in flight until its response has been handled */
|
|
43
|
+
_BetaToolRunner_compaction.set(this, { status: 'idle' });
|
|
44
|
+
/** Whether the last turn was paused; a scheduled compaction waits for it to be resumed */
|
|
45
|
+
_BetaToolRunner_turnPaused.set(this, false);
|
|
46
|
+
rejectCompactionParam(params);
|
|
47
|
+
tslib_1.__classPrivateFieldSet(this, _BetaToolRunner_state, {
|
|
48
|
+
params: {
|
|
49
|
+
// You can't clone the entire params since there are functions as handlers.
|
|
50
|
+
// You also don't really need to clone params.messages, but it probably will prevent a foot gun
|
|
51
|
+
// somewhere.
|
|
52
|
+
...params,
|
|
53
|
+
messages: structuredClone(params.messages),
|
|
54
|
+
},
|
|
55
|
+
}, "f");
|
|
56
|
+
// structuredClone drops symbol-keyed properties, so collect helper marks
|
|
57
|
+
// from the original params here — the create()-side collector won't see
|
|
58
|
+
// them on the cloned messages.
|
|
59
|
+
const collected = (0, stainless_helper_header_1.collectStainlessHelpers)(params.tools, params.messages);
|
|
60
|
+
tslib_1.__classPrivateFieldSet(this, _BetaToolRunner_options, {
|
|
61
|
+
...options,
|
|
62
|
+
headers: (0, headers_1.buildHeaders)([
|
|
63
|
+
(0, stainless_helper_header_1.helperHeader)('BetaToolRunner'),
|
|
64
|
+
collected.length ? { [stainless_helper_header_1.STAINLESS_HELPER_HEADER]: collected.join(', ') } : undefined,
|
|
65
|
+
options?.headers,
|
|
66
|
+
]),
|
|
67
|
+
}, "f");
|
|
68
|
+
tslib_1.__classPrivateFieldSet(this, _BetaToolRunner_completion, (0, promise_1.promiseWithResolvers)(), "f");
|
|
69
|
+
if (params.compactionControl?.enabled) {
|
|
70
|
+
console.warn('Anthropic: The `compactionControl` parameter is deprecated and will be removed in a future version. ' +
|
|
71
|
+
'Use server-side compaction instead by passing `edits: [{ type: "compact_20260112" }]` in the params passed to `toolRunner()`. ' +
|
|
72
|
+
'See https://platform.claude.com/docs/en/build-with-claude/compaction');
|
|
79
73
|
}
|
|
80
|
-
|
|
81
|
-
|
|
74
|
+
}
|
|
75
|
+
async *[(_BetaToolRunner_consumed = new WeakMap(), _BetaToolRunner_mutated = new WeakMap(), _BetaToolRunner_state = new WeakMap(), _BetaToolRunner_options = new WeakMap(), _BetaToolRunner_message = new WeakMap(), _BetaToolRunner_stream = new WeakMap(), _BetaToolRunner_toolResponse = new WeakMap(), _BetaToolRunner_completion = new WeakMap(), _BetaToolRunner_iterationCount = new WeakMap(), _BetaToolRunner_compaction = new WeakMap(), _BetaToolRunner_turnPaused = new WeakMap(), _BetaToolRunner_instances = new WeakSet(), _BetaToolRunner_checkAndCompact = async function _BetaToolRunner_checkAndCompact() {
|
|
76
|
+
const compactionControl = tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_state, "f").params.compactionControl;
|
|
77
|
+
if (!compactionControl || !compactionControl.enabled) {
|
|
82
78
|
return false;
|
|
83
79
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
if (messages[messages.length - 1].role === 'assistant') {
|
|
93
|
-
// Remove tool_use blocks from the last message to avoid 400 error
|
|
94
|
-
// (tool_use requires tool_result, which we don't have yet)
|
|
95
|
-
const lastMessage = messages[messages.length - 1];
|
|
96
|
-
if (Array.isArray(lastMessage.content)) {
|
|
97
|
-
const nonToolBlocks = lastMessage.content.filter((block) => block.type !== 'tool_use');
|
|
98
|
-
if (nonToolBlocks.length === 0) {
|
|
99
|
-
// If all blocks were tool_use, just remove the message entirely
|
|
100
|
-
messages.pop();
|
|
80
|
+
let tokensUsed = 0;
|
|
81
|
+
if (tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_message, "f") !== undefined) {
|
|
82
|
+
try {
|
|
83
|
+
const message = await tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_message, "f");
|
|
84
|
+
const totalInputTokens = message.usage.input_tokens +
|
|
85
|
+
(message.usage.cache_creation_input_tokens ?? 0) +
|
|
86
|
+
(message.usage.cache_read_input_tokens ?? 0);
|
|
87
|
+
tokensUsed = totalInputTokens + message.usage.output_tokens;
|
|
101
88
|
}
|
|
102
|
-
|
|
103
|
-
|
|
89
|
+
catch {
|
|
90
|
+
// If we can't get the message, skip compaction
|
|
91
|
+
return false;
|
|
104
92
|
}
|
|
105
93
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}, {
|
|
123
|
-
signal: tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_options, "f").signal,
|
|
124
|
-
headers: (0, headers_1.buildHeaders)([tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_options, "f").headers, (0, stainless_helper_header_1.helperHeader)('compaction')]),
|
|
125
|
-
});
|
|
126
|
-
if (response.content[0]?.type !== 'text') {
|
|
127
|
-
throw new error_1.AnthropicError('Expected text response for compaction');
|
|
128
|
-
}
|
|
129
|
-
tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_state, "f").params.messages = [
|
|
130
|
-
{
|
|
131
|
-
role: 'user',
|
|
132
|
-
content: response.content,
|
|
133
|
-
},
|
|
134
|
-
];
|
|
135
|
-
return true;
|
|
136
|
-
}, Symbol.asyncIterator)]() {
|
|
137
|
-
var _a;
|
|
138
|
-
if (tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_consumed, "f")) {
|
|
139
|
-
throw new error_1.AnthropicError('Cannot iterate over a consumed stream');
|
|
140
|
-
}
|
|
141
|
-
tslib_1.__classPrivateFieldSet(this, _BetaToolRunner_consumed, true, "f");
|
|
142
|
-
tslib_1.__classPrivateFieldSet(this, _BetaToolRunner_mutated, true, "f");
|
|
143
|
-
tslib_1.__classPrivateFieldSet(this, _BetaToolRunner_toolResponse, undefined, "f");
|
|
144
|
-
try {
|
|
145
|
-
while (true) {
|
|
146
|
-
let stream;
|
|
147
|
-
try {
|
|
148
|
-
if (tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_state, "f").params.max_iterations &&
|
|
149
|
-
tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_iterationCount, "f") >= tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_state, "f").params.max_iterations) {
|
|
150
|
-
break;
|
|
151
|
-
}
|
|
152
|
-
tslib_1.__classPrivateFieldSet(this, _BetaToolRunner_mutated, false, "f");
|
|
153
|
-
tslib_1.__classPrivateFieldSet(this, _BetaToolRunner_toolResponse, undefined, "f");
|
|
154
|
-
tslib_1.__classPrivateFieldSet(this, _BetaToolRunner_iterationCount, (_a = tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_iterationCount, "f"), _a++, _a), "f");
|
|
155
|
-
tslib_1.__classPrivateFieldSet(this, _BetaToolRunner_message, undefined, "f");
|
|
156
|
-
const { max_iterations, compactionControl, ...params } = tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_state, "f").params;
|
|
157
|
-
if (params.stream) {
|
|
158
|
-
stream = this.client.beta.messages.stream({ ...params }, tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_options, "f"));
|
|
159
|
-
tslib_1.__classPrivateFieldSet(this, _BetaToolRunner_message, stream.finalMessage(), "f");
|
|
160
|
-
// Make sure that this promise doesn't throw before we get the option to do something about it.
|
|
161
|
-
// Error will be caught when we call await this.#message ultimately
|
|
162
|
-
tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_message, "f").catch(() => { });
|
|
163
|
-
yield stream;
|
|
94
|
+
const threshold = compactionControl.contextTokenThreshold ?? CompactionControl_1.DEFAULT_TOKEN_THRESHOLD;
|
|
95
|
+
if (tokensUsed < threshold) {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
const model = compactionControl.model ?? tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_state, "f").params.model;
|
|
99
|
+
const summaryPrompt = compactionControl.summaryPrompt ?? CompactionControl_1.DEFAULT_SUMMARY_PROMPT;
|
|
100
|
+
const messages = tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_state, "f").params.messages;
|
|
101
|
+
if (messages[messages.length - 1].role === 'assistant') {
|
|
102
|
+
// Remove tool_use blocks from the last message to avoid 400 error
|
|
103
|
+
// (tool_use requires tool_result, which we don't have yet)
|
|
104
|
+
const lastMessage = messages[messages.length - 1];
|
|
105
|
+
if (Array.isArray(lastMessage.content)) {
|
|
106
|
+
const nonToolBlocks = lastMessage.content.filter((block) => block.type !== 'tool_use');
|
|
107
|
+
if (nonToolBlocks.length === 0) {
|
|
108
|
+
// If all blocks were tool_use, just remove the message entirely
|
|
109
|
+
messages.pop();
|
|
164
110
|
}
|
|
165
111
|
else {
|
|
166
|
-
|
|
167
|
-
yield tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_message, "f");
|
|
112
|
+
lastMessage.content = nonToolBlocks;
|
|
168
113
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
const response = await this.client.beta.messages.create({
|
|
117
|
+
model,
|
|
118
|
+
messages: [
|
|
119
|
+
...messages,
|
|
120
|
+
{
|
|
121
|
+
role: 'user',
|
|
122
|
+
content: [
|
|
123
|
+
{
|
|
124
|
+
type: 'text',
|
|
125
|
+
text: summaryPrompt,
|
|
126
|
+
},
|
|
127
|
+
],
|
|
128
|
+
},
|
|
129
|
+
],
|
|
130
|
+
max_tokens: tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_state, "f").params.max_tokens,
|
|
131
|
+
}, {
|
|
132
|
+
signal: tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_options, "f").signal,
|
|
133
|
+
headers: (0, headers_1.buildHeaders)([tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_options, "f").headers, (0, stainless_helper_header_1.helperHeader)('compaction')]),
|
|
134
|
+
});
|
|
135
|
+
if (response.content[0]?.type !== 'text') {
|
|
136
|
+
throw new error_1.AnthropicError('Expected text response for compaction');
|
|
137
|
+
}
|
|
138
|
+
tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_state, "f").params.messages = [
|
|
139
|
+
{
|
|
140
|
+
role: 'user',
|
|
141
|
+
content: response.content,
|
|
142
|
+
},
|
|
143
|
+
];
|
|
144
|
+
return true;
|
|
145
|
+
}, Symbol.asyncIterator)]() {
|
|
146
|
+
var _a;
|
|
147
|
+
if (tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_consumed, "f")) {
|
|
148
|
+
throw new error_1.AnthropicError('Cannot iterate over a consumed stream');
|
|
149
|
+
}
|
|
150
|
+
tslib_1.__classPrivateFieldSet(this, _BetaToolRunner_consumed, true, "f");
|
|
151
|
+
tslib_1.__classPrivateFieldSet(this, _BetaToolRunner_mutated, true, "f");
|
|
152
|
+
tslib_1.__classPrivateFieldSet(this, _BetaToolRunner_toolResponse, undefined, "f");
|
|
153
|
+
try {
|
|
154
|
+
while (true) {
|
|
155
|
+
try {
|
|
156
|
+
if (tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_state, "f").params.max_iterations &&
|
|
157
|
+
tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_iterationCount, "f") >= tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_state, "f").params.max_iterations) {
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
// The API can't compact a conversation that ends mid-turn, so a paused turn is resumed first.
|
|
161
|
+
if (tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_compaction, "f").status === 'scheduled' && !tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_turnPaused, "f")) {
|
|
162
|
+
yield* tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_instances, "m", _BetaToolRunner_compact).call(this, tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_compaction, "f").config);
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
tslib_1.__classPrivateFieldSet(this, _BetaToolRunner_mutated, false, "f");
|
|
166
|
+
tslib_1.__classPrivateFieldSet(this, _BetaToolRunner_toolResponse, undefined, "f");
|
|
167
|
+
tslib_1.__classPrivateFieldSet(this, _BetaToolRunner_iterationCount, (_a = tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_iterationCount, "f"), _a++, _a), "f");
|
|
168
|
+
tslib_1.__classPrivateFieldSet(this, _BetaToolRunner_message, undefined, "f");
|
|
169
|
+
const { max_iterations, compactionControl, ...params } = tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_state, "f").params;
|
|
170
|
+
yield* tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_instances, "m", _BetaToolRunner_send).call(this, params);
|
|
171
|
+
const isCompacted = await tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_instances, "m", _BetaToolRunner_checkAndCompact).call(this);
|
|
172
|
+
if (!isCompacted) {
|
|
173
|
+
if (!tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_mutated, "f")) {
|
|
174
|
+
const message = await tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_message, "f");
|
|
175
|
+
const nextStep = determineNextStepFromStopReason(message.stop_reason);
|
|
176
|
+
tslib_1.__classPrivateFieldSet(this, _BetaToolRunner_turnPaused, nextStep === 'resume', "f");
|
|
177
|
+
tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_state, "f").params.messages.push({ role: message.role, content: message.content });
|
|
178
|
+
// Container-bound server tools reject a follow-up request that omits the container the
|
|
179
|
+
// previous turn ran in, so carry its id forward unless the caller pinned one themselves.
|
|
180
|
+
const { container } = tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_state, "f").params;
|
|
181
|
+
if (message.container) {
|
|
182
|
+
if (container == null) {
|
|
183
|
+
tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_state, "f").params.container = message.container.id;
|
|
184
|
+
}
|
|
185
|
+
else if (typeof container === 'object' && container.id == null) {
|
|
186
|
+
tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_state, "f").params.container = { ...container, id: message.container.id };
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
if (nextStep === 'stop') {
|
|
190
|
+
yield* tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_instances, "m", _BetaToolRunner_compactAfterFinalTurn).call(this);
|
|
191
|
+
break;
|
|
181
192
|
}
|
|
182
|
-
|
|
183
|
-
|
|
193
|
+
if (nextStep === 'resume') {
|
|
194
|
+
continue;
|
|
184
195
|
}
|
|
185
196
|
}
|
|
186
|
-
|
|
187
|
-
|
|
197
|
+
else {
|
|
198
|
+
// The caller has taken over the history, so the last response no longer says how it ends.
|
|
199
|
+
tslib_1.__classPrivateFieldSet(this, _BetaToolRunner_turnPaused, false, "f");
|
|
188
200
|
}
|
|
189
|
-
|
|
190
|
-
|
|
201
|
+
const toolMessage = await tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_instances, "m", _BetaToolRunner_generateToolResponse).call(this, tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_state, "f").params.messages.at(-1));
|
|
202
|
+
if (toolMessage) {
|
|
203
|
+
tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_state, "f").params.messages.push(toolMessage);
|
|
204
|
+
}
|
|
205
|
+
else if (!tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_mutated, "f")) {
|
|
206
|
+
yield* tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_instances, "m", _BetaToolRunner_compactAfterFinalTurn).call(this);
|
|
207
|
+
break;
|
|
191
208
|
}
|
|
192
|
-
}
|
|
193
|
-
const toolMessage = await tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_instances, "m", _BetaToolRunner_generateToolResponse).call(this, tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_state, "f").params.messages.at(-1));
|
|
194
|
-
if (toolMessage) {
|
|
195
|
-
tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_state, "f").params.messages.push(toolMessage);
|
|
196
|
-
}
|
|
197
|
-
else if (!tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_mutated, "f")) {
|
|
198
|
-
break;
|
|
199
209
|
}
|
|
200
210
|
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
stream.abort();
|
|
211
|
+
finally {
|
|
212
|
+
tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_stream, "f")?.abort();
|
|
213
|
+
tslib_1.__classPrivateFieldSet(this, _BetaToolRunner_stream, undefined, "f");
|
|
205
214
|
}
|
|
206
215
|
}
|
|
216
|
+
if (!tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_message, "f")) {
|
|
217
|
+
throw new error_1.AnthropicError('ToolRunner concluded without a message from the server');
|
|
218
|
+
}
|
|
219
|
+
tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_completion, "f").resolve(await tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_message, "f"));
|
|
207
220
|
}
|
|
208
|
-
|
|
209
|
-
|
|
221
|
+
catch (error) {
|
|
222
|
+
tslib_1.__classPrivateFieldSet(this, _BetaToolRunner_consumed, false, "f");
|
|
223
|
+
// Silence unhandled promise errors
|
|
224
|
+
tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_completion, "f").promise.catch(() => { });
|
|
225
|
+
tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_completion, "f").reject(error);
|
|
226
|
+
tslib_1.__classPrivateFieldSet(this, _BetaToolRunner_completion, (0, promise_1.promiseWithResolvers)(), "f");
|
|
227
|
+
throw error;
|
|
210
228
|
}
|
|
211
|
-
tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_completion, "f").resolve(await tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_message, "f"));
|
|
212
229
|
}
|
|
213
|
-
|
|
214
|
-
tslib_1.
|
|
215
|
-
|
|
216
|
-
tslib_1.__classPrivateFieldGet(this,
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
230
|
+
setMessagesParams(paramsOrMutator) {
|
|
231
|
+
const params = typeof paramsOrMutator === 'function' ? paramsOrMutator(tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_state, "f").params) : paramsOrMutator;
|
|
232
|
+
rejectCompactionParam(params);
|
|
233
|
+
if (tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_compaction, "f").status !== 'idle') {
|
|
234
|
+
rejectCompactionEdit(params);
|
|
235
|
+
}
|
|
236
|
+
if (tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_compaction, "f").status === 'in_flight' && params.messages !== tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_state, "f").params.messages) {
|
|
237
|
+
throw new error_1.AnthropicError("Message params can't be changed while the conversation is being compacted, because the compaction " +
|
|
238
|
+
'response is about to replace them. Change them after this iteration instead.');
|
|
239
|
+
}
|
|
240
|
+
tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_state, "f").params = params;
|
|
241
|
+
tslib_1.__classPrivateFieldSet(this, _BetaToolRunner_mutated, true, "f");
|
|
242
|
+
// Invalidate cached tool response since parameters changed
|
|
243
|
+
tslib_1.__classPrivateFieldSet(this, _BetaToolRunner_toolResponse, undefined, "f");
|
|
220
244
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
245
|
+
setRequestOptions(optionsOrMutator) {
|
|
246
|
+
if (typeof optionsOrMutator === 'function') {
|
|
247
|
+
tslib_1.__classPrivateFieldSet(this, _BetaToolRunner_options, optionsOrMutator(tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_options, "f")), "f");
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
tslib_1.__classPrivateFieldSet(this, _BetaToolRunner_options, { ...tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_options, "f"), ...optionsOrMutator }, "f");
|
|
251
|
+
}
|
|
225
252
|
}
|
|
226
|
-
|
|
227
|
-
|
|
253
|
+
/**
|
|
254
|
+
* Get the tool response for the last message from the assistant.
|
|
255
|
+
* Avoids redundant tool executions by caching results.
|
|
256
|
+
*
|
|
257
|
+
* @returns A promise that resolves to a BetaMessageParam containing tool results, or null if no tools need to be executed
|
|
258
|
+
*
|
|
259
|
+
* @example
|
|
260
|
+
* const toolResponse = await runner.generateToolResponse();
|
|
261
|
+
* if (toolResponse) {
|
|
262
|
+
* console.log('Tool results:', toolResponse.content);
|
|
263
|
+
* }
|
|
264
|
+
*/
|
|
265
|
+
async generateToolResponse(signal = tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_options, "f").signal) {
|
|
266
|
+
const message = (await tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_message, "f")) ?? this.params.messages.at(-1);
|
|
267
|
+
if (!message) {
|
|
268
|
+
return null;
|
|
269
|
+
}
|
|
270
|
+
return tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_instances, "m", _BetaToolRunner_generateToolResponse).call(this, message, signal);
|
|
228
271
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
272
|
+
/**
|
|
273
|
+
* Wait for the async iterator to complete. This works even if the async iterator hasn't yet started, and
|
|
274
|
+
* will wait for an instance to start and go to completion.
|
|
275
|
+
*
|
|
276
|
+
* @returns A promise that resolves to the final BetaMessage when the iterator completes
|
|
277
|
+
*
|
|
278
|
+
* @example
|
|
279
|
+
* // Start consuming the iterator
|
|
280
|
+
* for await (const message of runner) {
|
|
281
|
+
* console.log('Message:', message.content);
|
|
282
|
+
* }
|
|
283
|
+
*
|
|
284
|
+
* // Meanwhile, wait for completion from another part of the code
|
|
285
|
+
* const finalMessage = await runner.done();
|
|
286
|
+
* console.log('Final response:', finalMessage.content);
|
|
287
|
+
*/
|
|
288
|
+
done() {
|
|
289
|
+
return tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_completion, "f").promise;
|
|
236
290
|
}
|
|
237
|
-
|
|
238
|
-
|
|
291
|
+
/**
|
|
292
|
+
* Returns a promise indicating that the stream is done. Unlike .done(), this will eagerly read the stream:
|
|
293
|
+
* * If the iterator has not been consumed, consume the entire iterator and return the final message from the
|
|
294
|
+
* assistant.
|
|
295
|
+
* * If the iterator has been consumed, waits for it to complete and returns the final message.
|
|
296
|
+
*
|
|
297
|
+
* @returns A promise that resolves to the final BetaMessage from the conversation
|
|
298
|
+
* @throws {AnthropicError} If no messages were processed during the conversation
|
|
299
|
+
*
|
|
300
|
+
* @example
|
|
301
|
+
* const finalMessage = await runner.runUntilDone();
|
|
302
|
+
* console.log('Final response:', finalMessage.content);
|
|
303
|
+
*/
|
|
304
|
+
async runUntilDone() {
|
|
305
|
+
// If not yet consumed, start consuming and wait for completion
|
|
306
|
+
if (!tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_consumed, "f")) {
|
|
307
|
+
for await (const _ of this) {
|
|
308
|
+
// Iterator naturally populates this.#message
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
// If consumed but not completed, wait for completion
|
|
312
|
+
return this.done();
|
|
239
313
|
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
*/
|
|
253
|
-
async generateToolResponse(signal = tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_options, "f").signal) {
|
|
254
|
-
const message = (await tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_message, "f")) ?? this.params.messages.at(-1);
|
|
255
|
-
if (!message) {
|
|
256
|
-
return null;
|
|
314
|
+
/**
|
|
315
|
+
* Get the current parameters being used by the ToolRunner.
|
|
316
|
+
*
|
|
317
|
+
* @returns A readonly view of the current ToolRunnerParams
|
|
318
|
+
*
|
|
319
|
+
* @example
|
|
320
|
+
* const currentParams = runner.params;
|
|
321
|
+
* console.log('Current model:', currentParams.model);
|
|
322
|
+
* console.log('Message count:', currentParams.messages.length);
|
|
323
|
+
*/
|
|
324
|
+
get params() {
|
|
325
|
+
return tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_state, "f").params;
|
|
257
326
|
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
327
|
+
/**
|
|
328
|
+
* Add one or more messages to the conversation history.
|
|
329
|
+
*
|
|
330
|
+
* @param messages - One or more BetaMessageParam objects to add to the conversation
|
|
331
|
+
*
|
|
332
|
+
* @example
|
|
333
|
+
* runner.pushMessages(
|
|
334
|
+
* { role: 'user', content: 'Also, what about the weather in NYC?' }
|
|
335
|
+
* );
|
|
336
|
+
*
|
|
337
|
+
* @example
|
|
338
|
+
* // Adding multiple messages
|
|
339
|
+
* runner.pushMessages(
|
|
340
|
+
* { role: 'user', content: 'What about NYC?' },
|
|
341
|
+
* { role: 'user', content: 'And Boston?' }
|
|
342
|
+
* );
|
|
343
|
+
*/
|
|
344
|
+
pushMessages(...messages) {
|
|
345
|
+
this.setMessagesParams((params) => ({
|
|
346
|
+
...params,
|
|
347
|
+
messages: [...params.messages, ...messages],
|
|
348
|
+
}));
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Schedule a compaction of the conversation. Once the current turn has finished, including any tool
|
|
352
|
+
* calls, the runner requests a summary and replaces the message history with the compaction response,
|
|
353
|
+
* which is yielded like any other message. Requires the `compact-2026-09-04` beta.
|
|
354
|
+
*
|
|
355
|
+
* @param compaction - The config to send, as `messages.create()` takes it. Defaults to `{ type: 'summarize' }`
|
|
356
|
+
*
|
|
357
|
+
* @example
|
|
358
|
+
* for await (const message of runner) {
|
|
359
|
+
* if (message.usage.input_tokens > 100_000) {
|
|
360
|
+
* runner.compactBeforeNextTurn();
|
|
361
|
+
* }
|
|
362
|
+
* }
|
|
363
|
+
*/
|
|
364
|
+
compactBeforeNextTurn(compaction) {
|
|
365
|
+
if (tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_compaction, "f").status === 'in_flight') {
|
|
366
|
+
return;
|
|
297
367
|
}
|
|
368
|
+
rejectCompactionEdit(tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_state, "f").params);
|
|
369
|
+
tslib_1.__classPrivateFieldSet(this, _BetaToolRunner_compaction, { status: 'scheduled', config: compaction ?? { type: 'summarize' } }, "f");
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Makes the ToolRunner directly awaitable, equivalent to calling .runUntilDone()
|
|
373
|
+
* This allows using `await runner` instead of `await runner.runUntilDone()`
|
|
374
|
+
*/
|
|
375
|
+
then(onfulfilled, onrejected) {
|
|
376
|
+
return this.runUntilDone().then(onfulfilled, onrejected);
|
|
298
377
|
}
|
|
299
|
-
// If consumed but not completed, wait for completion
|
|
300
|
-
return this.done();
|
|
301
|
-
}
|
|
302
|
-
/**
|
|
303
|
-
* Get the current parameters being used by the ToolRunner.
|
|
304
|
-
*
|
|
305
|
-
* @returns A readonly view of the current ToolRunnerParams
|
|
306
|
-
*
|
|
307
|
-
* @example
|
|
308
|
-
* const currentParams = runner.params;
|
|
309
|
-
* console.log('Current model:', currentParams.model);
|
|
310
|
-
* console.log('Message count:', currentParams.messages.length);
|
|
311
|
-
*/
|
|
312
|
-
get params() {
|
|
313
|
-
return tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_state, "f").params;
|
|
314
|
-
}
|
|
315
|
-
/**
|
|
316
|
-
* Add one or more messages to the conversation history.
|
|
317
|
-
*
|
|
318
|
-
* @param messages - One or more BetaMessageParam objects to add to the conversation
|
|
319
|
-
*
|
|
320
|
-
* @example
|
|
321
|
-
* runner.pushMessages(
|
|
322
|
-
* { role: 'user', content: 'Also, what about the weather in NYC?' }
|
|
323
|
-
* );
|
|
324
|
-
*
|
|
325
|
-
* @example
|
|
326
|
-
* // Adding multiple messages
|
|
327
|
-
* runner.pushMessages(
|
|
328
|
-
* { role: 'user', content: 'What about NYC?' },
|
|
329
|
-
* { role: 'user', content: 'And Boston?' }
|
|
330
|
-
* );
|
|
331
|
-
*/
|
|
332
|
-
pushMessages(...messages) {
|
|
333
|
-
this.setMessagesParams((params) => ({
|
|
334
|
-
...params,
|
|
335
|
-
messages: [...params.messages, ...messages],
|
|
336
|
-
}));
|
|
337
378
|
}
|
|
379
|
+
_BetaToolRunner_send =
|
|
338
380
|
/**
|
|
339
|
-
*
|
|
340
|
-
*
|
|
381
|
+
* Sends one request and yields its message, or its stream when streaming. `#message` and `#stream` are set
|
|
382
|
+
* before the yield, so they are there while the caller handles the item; the loop aborts the stream at the
|
|
383
|
+
* end of the iteration.
|
|
341
384
|
*/
|
|
342
|
-
|
|
343
|
-
|
|
385
|
+
async function* _BetaToolRunner_send(params) {
|
|
386
|
+
if (params.stream) {
|
|
387
|
+
tslib_1.__classPrivateFieldSet(this, _BetaToolRunner_stream, this.client.beta.messages.stream({ ...params }, tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_options, "f")), "f");
|
|
388
|
+
tslib_1.__classPrivateFieldSet(this, _BetaToolRunner_message, tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_stream, "f").finalMessage(), "f");
|
|
389
|
+
// Make sure that this promise doesn't throw before we get the option to do something about it.
|
|
390
|
+
// Error will be caught when we call await this.#message ultimately
|
|
391
|
+
tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_message, "f").catch(() => { });
|
|
392
|
+
yield tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_stream, "f");
|
|
393
|
+
}
|
|
394
|
+
else {
|
|
395
|
+
tslib_1.__classPrivateFieldSet(this, _BetaToolRunner_message, this.client.beta.messages.create({ ...params, stream: false }, tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_options, "f")), "f");
|
|
396
|
+
yield tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_message, "f");
|
|
397
|
+
}
|
|
398
|
+
}, _BetaToolRunner_compact = async function* _BetaToolRunner_compact(compaction) {
|
|
399
|
+
rejectCompactionEdit(tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_state, "f").params);
|
|
400
|
+
// The API refuses `compaction` alongside `context_management`; later requests keep it.
|
|
401
|
+
const { max_iterations, compactionControl, context_management, ...params } = tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_state, "f").params;
|
|
402
|
+
tslib_1.__classPrivateFieldSet(this, _BetaToolRunner_compaction, { status: 'in_flight' }, "f");
|
|
403
|
+
tslib_1.__classPrivateFieldSet(this, _BetaToolRunner_toolResponse, undefined, "f");
|
|
404
|
+
const lastMessage = tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_message, "f");
|
|
405
|
+
try {
|
|
406
|
+
yield* tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_instances, "m", _BetaToolRunner_send).call(this, { ...params, compaction });
|
|
407
|
+
const message = await tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_message, "f");
|
|
408
|
+
if (message.content.some((block) => block.type === 'compaction' && block.content)) {
|
|
409
|
+
// The response has to be sent back as it came, first, replacing the messages it summarizes.
|
|
410
|
+
tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_state, "f").params.messages = [{ role: message.role, content: message.content }];
|
|
411
|
+
}
|
|
412
|
+
else {
|
|
413
|
+
(0, log_1.loggerFor)(this.client).warn('Compaction produced no summary; keeping the conversation as it is.');
|
|
414
|
+
// If the run ends here, `done()` resolves to the last real message rather than this response.
|
|
415
|
+
tslib_1.__classPrivateFieldSet(this, _BetaToolRunner_message, lastMessage, "f");
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
finally {
|
|
419
|
+
tslib_1.__classPrivateFieldSet(this, _BetaToolRunner_compaction, { status: 'idle' }, "f");
|
|
420
|
+
}
|
|
421
|
+
}, _BetaToolRunner_compactAfterFinalTurn = async function* _BetaToolRunner_compactAfterFinalTurn() {
|
|
422
|
+
if (tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_compaction, "f").status !== 'scheduled') {
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
425
|
+
const lastContent = tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_state, "f").params.messages.at(-1)?.content;
|
|
426
|
+
if (Array.isArray(lastContent) && lastContent.some((block) => block.type === 'tool_use')) {
|
|
427
|
+
// A turn that was cut short can end with tool calls that are never run, and the API can't
|
|
428
|
+
// compact a conversation whose last turn has an unanswered tool call.
|
|
429
|
+
(0, log_1.loggerFor)(this.client).warn('The pending compaction was skipped because the last turn ended with tool calls that were not run. ' +
|
|
430
|
+
'Call `compactBeforeNextTurn()` again if you continue the conversation.');
|
|
431
|
+
tslib_1.__classPrivateFieldSet(this, _BetaToolRunner_compaction, { status: 'idle' }, "f");
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
yield* tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_instances, "m", _BetaToolRunner_compact).call(this, tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_compaction, "f").config);
|
|
435
|
+
}, _BetaToolRunner_generateToolResponse = async function _BetaToolRunner_generateToolResponse(lastMessage, signal = tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_options, "f").signal) {
|
|
436
|
+
if (tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_toolResponse, "f") !== undefined) {
|
|
437
|
+
return tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_toolResponse, "f");
|
|
438
|
+
}
|
|
439
|
+
tslib_1.__classPrivateFieldSet(this, _BetaToolRunner_toolResponse, generateToolResponse(tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_state, "f").params, lastMessage, {
|
|
440
|
+
...tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_options, "f"),
|
|
441
|
+
signal,
|
|
442
|
+
}), "f");
|
|
443
|
+
return tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_toolResponse, "f");
|
|
444
|
+
};
|
|
445
|
+
return BetaToolRunner;
|
|
446
|
+
})();
|
|
447
|
+
exports.BetaToolRunner = BetaToolRunner;
|
|
448
|
+
function rejectCompactionParam(params) {
|
|
449
|
+
if ('compaction' in params && params.compaction != null) {
|
|
450
|
+
throw new error_1.AnthropicError('`compaction` cannot be set on a tool runner: every request in the loop would compact again. ' +
|
|
451
|
+
'Call `runner.compactBeforeNextTurn()` when the conversation should be compacted instead.');
|
|
344
452
|
}
|
|
345
453
|
}
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
454
|
+
function rejectCompactionEdit(params) {
|
|
455
|
+
// The compaction request is sent without `context_management`, so the API can't refuse the pair there:
|
|
456
|
+
// it would run and bill the compaction, then refuse the next request.
|
|
457
|
+
if (params.context_management?.edits?.some((edit) => edit.type.startsWith('compact_'))) {
|
|
458
|
+
throw new error_1.AnthropicError("`compactBeforeNextTurn()` can't be used while `context_management` has a compaction edit, " +
|
|
459
|
+
"because the API doesn't accept a compaction block together with one. Remove the edit first.");
|
|
350
460
|
}
|
|
351
|
-
|
|
352
|
-
...tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_options, "f"),
|
|
353
|
-
signal,
|
|
354
|
-
}), "f");
|
|
355
|
-
return tslib_1.__classPrivateFieldGet(this, _BetaToolRunner_toolResponse, "f");
|
|
356
|
-
};
|
|
461
|
+
}
|
|
357
462
|
async function generateToolResponse(params, lastMessage = params.messages.at(-1), requestOptions) {
|
|
358
463
|
// Only process if the last message is from the assistant and has tool use blocks
|
|
359
464
|
if (!lastMessage ||
|