@anthropic-ai/sdk 0.114.0 → 0.115.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.
Files changed (116) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/client.d.mts.map +1 -1
  3. package/client.d.ts.map +1 -1
  4. package/client.js +8 -1
  5. package/client.js.map +1 -1
  6. package/client.mjs +8 -1
  7. package/client.mjs.map +1 -1
  8. package/core/streaming.d.mts.map +1 -1
  9. package/core/streaming.d.ts.map +1 -1
  10. package/core/streaming.js +3 -0
  11. package/core/streaming.js.map +1 -1
  12. package/core/streaming.mjs +3 -0
  13. package/core/streaming.mjs.map +1 -1
  14. package/internal/parse.d.mts.map +1 -1
  15. package/internal/parse.d.ts.map +1 -1
  16. package/internal/parse.js +10 -1
  17. package/internal/parse.js.map +1 -1
  18. package/internal/parse.mjs +10 -1
  19. package/internal/parse.mjs.map +1 -1
  20. package/internal/request-signal.d.mts +4 -0
  21. package/internal/request-signal.d.mts.map +1 -0
  22. package/internal/request-signal.d.ts +4 -0
  23. package/internal/request-signal.d.ts.map +1 -0
  24. package/internal/request-signal.js +50 -0
  25. package/internal/request-signal.js.map +1 -0
  26. package/internal/request-signal.mjs +45 -0
  27. package/internal/request-signal.mjs.map +1 -0
  28. package/lib/BetaMessageStream.d.mts.map +1 -1
  29. package/lib/BetaMessageStream.d.ts.map +1 -1
  30. package/lib/BetaMessageStream.js +3 -0
  31. package/lib/BetaMessageStream.js.map +1 -1
  32. package/lib/BetaMessageStream.mjs +3 -0
  33. package/lib/BetaMessageStream.mjs.map +1 -1
  34. package/lib/middleware.d.mts +5 -3
  35. package/lib/middleware.d.mts.map +1 -1
  36. package/lib/middleware.d.ts +5 -3
  37. package/lib/middleware.d.ts.map +1 -1
  38. package/lib/middleware.js +58 -15
  39. package/lib/middleware.js.map +1 -1
  40. package/lib/middleware.mjs +58 -15
  41. package/lib/middleware.mjs.map +1 -1
  42. package/lib/tools/BetaToolRunner.d.mts.map +1 -1
  43. package/lib/tools/BetaToolRunner.d.ts.map +1 -1
  44. package/lib/tools/BetaToolRunner.js +80 -7
  45. package/lib/tools/BetaToolRunner.js.map +1 -1
  46. package/lib/tools/BetaToolRunner.mjs +80 -7
  47. package/lib/tools/BetaToolRunner.mjs.map +1 -1
  48. package/package.json +1 -1
  49. package/resources/beta/agents/agents.d.mts +1 -1
  50. package/resources/beta/agents/agents.d.mts.map +1 -1
  51. package/resources/beta/agents/agents.d.ts +1 -1
  52. package/resources/beta/agents/agents.d.ts.map +1 -1
  53. package/resources/beta/agents/agents.js.map +1 -1
  54. package/resources/beta/agents/agents.mjs.map +1 -1
  55. package/resources/beta/beta.d.mts +3 -3
  56. package/resources/beta/beta.d.mts.map +1 -1
  57. package/resources/beta/beta.d.ts +3 -3
  58. package/resources/beta/beta.d.ts.map +1 -1
  59. package/resources/beta/beta.js.map +1 -1
  60. package/resources/beta/beta.mjs.map +1 -1
  61. package/resources/beta/index.d.mts +1 -1
  62. package/resources/beta/index.d.mts.map +1 -1
  63. package/resources/beta/index.d.ts +1 -1
  64. package/resources/beta/index.d.ts.map +1 -1
  65. package/resources/beta/index.js.map +1 -1
  66. package/resources/beta/index.mjs.map +1 -1
  67. package/resources/beta/messages/batches.d.mts +4 -3
  68. package/resources/beta/messages/batches.d.mts.map +1 -1
  69. package/resources/beta/messages/batches.d.ts +4 -3
  70. package/resources/beta/messages/batches.d.ts.map +1 -1
  71. package/resources/beta/messages/index.d.mts +1 -1
  72. package/resources/beta/messages/index.d.mts.map +1 -1
  73. package/resources/beta/messages/index.d.ts +1 -1
  74. package/resources/beta/messages/index.d.ts.map +1 -1
  75. package/resources/beta/messages/index.js.map +1 -1
  76. package/resources/beta/messages/index.mjs.map +1 -1
  77. package/resources/beta/messages/messages.d.mts +154 -6
  78. package/resources/beta/messages/messages.d.mts.map +1 -1
  79. package/resources/beta/messages/messages.d.ts +154 -6
  80. package/resources/beta/messages/messages.d.ts.map +1 -1
  81. package/resources/beta/messages/messages.js.map +1 -1
  82. package/resources/beta/messages/messages.mjs.map +1 -1
  83. package/resources/messages/messages.d.mts +1 -1
  84. package/resources/messages/messages.d.mts.map +1 -1
  85. package/resources/messages/messages.d.ts +1 -1
  86. package/resources/messages/messages.d.ts.map +1 -1
  87. package/resources/messages/messages.js.map +1 -1
  88. package/resources/messages/messages.mjs.map +1 -1
  89. package/src/client.ts +13 -1
  90. package/src/core/streaming.ts +3 -0
  91. package/src/internal/parse.ts +10 -1
  92. package/src/internal/request-signal.ts +68 -0
  93. package/src/lib/BetaMessageStream.ts +4 -0
  94. package/src/lib/middleware.ts +61 -16
  95. package/src/lib/tools/BetaToolRunner.ts +101 -8
  96. package/src/resources/beta/agents/agents.ts +1 -0
  97. package/src/resources/beta/beta.ts +22 -0
  98. package/src/resources/beta/index.ts +10 -0
  99. package/src/resources/beta/messages/batches.ts +4 -3
  100. package/src/resources/beta/messages/index.ts +10 -0
  101. package/src/resources/beta/messages/messages.ts +199 -4
  102. package/src/resources/messages/messages.ts +1 -0
  103. package/src/version.ts +1 -1
  104. package/version.d.mts +1 -1
  105. package/version.d.ts +1 -1
  106. package/version.js +1 -1
  107. package/version.mjs +1 -1
  108. package/lib/tools/ToolRunner.d.mts +0 -132
  109. package/lib/tools/ToolRunner.d.mts.map +0 -1
  110. package/lib/tools/ToolRunner.d.ts +0 -132
  111. package/lib/tools/ToolRunner.d.ts.map +0 -1
  112. package/lib/tools/ToolRunner.js +0 -294
  113. package/lib/tools/ToolRunner.js.map +0 -1
  114. package/lib/tools/ToolRunner.mjs +0 -290
  115. package/lib/tools/ToolRunner.mjs.map +0 -1
  116. package/src/lib/tools/ToolRunner.ts +0 -381
@@ -1441,6 +1441,8 @@ export type BetaContentBlockParam =
1441
1441
  | BetaContainerUploadBlockParam
1442
1442
  | BetaCompactionBlockParam
1443
1443
  | BetaMidConversationSystemBlockParam
1444
+ | BetaRequestToolAdditionBlock
1445
+ | BetaRequestToolRemovalBlock
1444
1446
  | BetaFallbackBlockParam;
1445
1447
 
1446
1448
  export interface BetaContentBlockSource {
@@ -1631,6 +1633,94 @@ export interface BetaFallbackBlockParam {
1631
1633
  trigger?: unknown;
1632
1634
  }
1633
1635
 
1636
+ /**
1637
+ * No reprice was applied; `reason` says why.
1638
+ */
1639
+ export interface BetaFallbackCreditNotApplied {
1640
+ /**
1641
+ * Why the reprice was not applied.
1642
+ *
1643
+ * A closed enum; additions to the redemption-check vocabulary arrive as deliberate
1644
+ * schema updates.
1645
+ */
1646
+ reason:
1647
+ | 'body_mismatch'
1648
+ | 'continuation_excluded'
1649
+ | 'continuation_only'
1650
+ | 'expired'
1651
+ | 'invalid_target_model'
1652
+ | 'not_enabled'
1653
+ | 'reprice_unavailable'
1654
+ | 'temporarily_unavailable'
1655
+ | 'variant_fields_present'
1656
+ | 'wrong_organization'
1657
+ | 'wrong_platform'
1658
+ | 'wrong_workspace';
1659
+
1660
+ type: 'not_applied';
1661
+
1662
+ /**
1663
+ * Request fields to remove before retrying, so the retry can redeem this token.
1664
+ *
1665
+ * Present exactly when `reason` is `variant_fields_present` — never null, never an
1666
+ * empty array; absent otherwise. Fields are named only from your own request, and
1667
+ * only after the sealed variant hash matched. A served best-effort retry has
1668
+ * already been billed at normal price; nothing redeems retroactively, but a
1669
+ * corrected re-send inside the token's five-minute window can still redeem.
1670
+ */
1671
+ remove_to_redeem?: Array<string> | null;
1672
+ }
1673
+
1674
+ /**
1675
+ * The reprice was applied: the retry is billed as if the conversation had been on
1676
+ * the retry model all along.
1677
+ */
1678
+ export interface BetaFallbackCreditRedeemed {
1679
+ type: 'redeemed';
1680
+ }
1681
+
1682
+ /**
1683
+ * Object form of `fallback_credit_token`: the token plus a redemption mode.
1684
+ *
1685
+ * Requires `anthropic-beta: fallback-credit-2026-07-01`; without that header the
1686
+ * field accepts the bare string only. The bare string and the mode-less object are
1687
+ * equivalent (both select `strict`), so wrapping an existing token changes nothing
1688
+ * by itself.
1689
+ */
1690
+ export interface BetaFallbackCreditTokenParam {
1691
+ /**
1692
+ * The opaque `fallback_credit_token` from a prior refusal's `stop_details` — the
1693
+ * same string the bare-string form carries.
1694
+ */
1695
+ token: string;
1696
+
1697
+ /**
1698
+ * How a failing token affects the retry. `strict` (the default, and the
1699
+ * bare-string behavior): a failing redemption is a 400 and the retry is not
1700
+ * served. `best_effort`: the retry is served either way — a token-layer failure no
1701
+ * longer rejects the request; the retry proceeds at normal price and the outcome
1702
+ * is reported on the response's `usage.fallback_credit`. Two failures stay hard in
1703
+ * both modes: a malformed token, and combining `fallback_credit_token` with
1704
+ * `fallbacks`.
1705
+ */
1706
+ mode?: 'strict' | 'best_effort';
1707
+ }
1708
+
1709
+ /**
1710
+ * Outcome of the `fallback_credit_token` presented on this request.
1711
+ */
1712
+ export interface BetaFallbackCreditUsage {
1713
+ /**
1714
+ * Whether the fallback-credit reprice was applied to this response's billing.
1715
+ *
1716
+ * A union discriminated on `type`. `redeemed`: the retry is billed as if the
1717
+ * conversation had been on the retry model all along — including when the
1718
+ * resulting shift is zero because there was nothing to move. `not_applied`: no
1719
+ * reprice was applied; the arm's `reason` says why.
1720
+ */
1721
+ status: BetaFallbackCreditRedeemed | BetaFallbackCreditNotApplied;
1722
+ }
1723
+
1634
1724
  /**
1635
1725
  * Identifies one hop of a fallback transition.
1636
1726
  */
@@ -1765,6 +1855,14 @@ export interface BetaFallbackRefusalTrigger {
1765
1855
  type: 'refusal';
1766
1856
  }
1767
1857
 
1858
+ /**
1859
+ * Opt-in server-side retry on one or more substitute models when the requested
1860
+ * model declines for policy reasons. Tried in order: if the first entry also
1861
+ * declines, the second is tried, and so on. The string "default" requests the
1862
+ * requested model's server-defined default fallback configuration.
1863
+ */
1864
+ export type BetaFallbacksParam = Array<BetaFallbackParam> | 'default';
1865
+
1768
1866
  export interface BetaFileDocumentSource {
1769
1867
  file_id: string;
1770
1868
 
@@ -2225,6 +2323,11 @@ export interface BetaMessageDeltaUsage {
2225
2323
  */
2226
2324
  cache_read_input_tokens: number | null;
2227
2325
 
2326
+ /**
2327
+ * Outcome of the `fallback_credit_token` presented on this request.
2328
+ */
2329
+ fallback_credit: BetaFallbackCreditUsage | null;
2330
+
2228
2331
  /**
2229
2332
  * The cumulative number of input tokens which were used.
2230
2333
  */
@@ -2347,7 +2450,7 @@ export interface BetaMidConversationSystemBlockParam {
2347
2450
  /**
2348
2451
  * System instruction text blocks.
2349
2452
  */
2350
- content: Array<BetaTextBlockParam>;
2453
+ content: Array<BetaTextBlockParam | BetaRequestToolAdditionBlock | BetaRequestToolRemovalBlock>;
2351
2454
 
2352
2455
  type: 'mid_conv_system';
2353
2456
 
@@ -2669,6 +2772,50 @@ export interface BetaRequestMCPToolResultBlockParam {
2669
2772
  is_error?: boolean;
2670
2773
  }
2671
2774
 
2775
+ /**
2776
+ * Mid-conversation directive to surface a declared tool.
2777
+ *
2778
+ * `tool` references a tool (or MCP toolset) by name from the request's `tools`; it
2779
+ * is offered to the model from this point in the conversation onward.
2780
+ */
2781
+ export interface BetaRequestToolAdditionBlock {
2782
+ /**
2783
+ * Reference to a single tool the caller declared directly in `tools[]`. Does not
2784
+ * accept the composed `{server}_{name}` form the server assigns to MCP-resolved
2785
+ * tools — use `mcp_tool_reference` or `mcp_toolset_reference` for those.
2786
+ */
2787
+ tool: BetaToolChangeToolReference | BetaToolChangeMCPToolReference | BetaToolChangeMCPToolsetReference;
2788
+
2789
+ type: 'tool_addition';
2790
+
2791
+ /**
2792
+ * Create a cache control breakpoint at this content block.
2793
+ */
2794
+ cache_control?: BetaCacheControlEphemeral | null;
2795
+ }
2796
+
2797
+ /**
2798
+ * Mid-conversation directive to withdraw a tool.
2799
+ *
2800
+ * `tool` references a tool (or MCP toolset) by name from the request's `tools`; it
2801
+ * is no longer offered to the model from this point in the conversation onward.
2802
+ */
2803
+ export interface BetaRequestToolRemovalBlock {
2804
+ /**
2805
+ * Reference to a single tool the caller declared directly in `tools[]`. Does not
2806
+ * accept the composed `{server}_{name}` form the server assigns to MCP-resolved
2807
+ * tools — use `mcp_tool_reference` or `mcp_toolset_reference` for those.
2808
+ */
2809
+ tool: BetaToolChangeToolReference | BetaToolChangeMCPToolReference | BetaToolChangeMCPToolsetReference;
2810
+
2811
+ type: 'tool_removal';
2812
+
2813
+ /**
2814
+ * Create a cache control breakpoint at this content block.
2815
+ */
2816
+ cache_control?: BetaCacheControlEphemeral | null;
2817
+ }
2818
+
2672
2819
  export interface BetaSearchResultBlockParam {
2673
2820
  content: Array<BetaTextBlockParam>;
2674
2821
 
@@ -3253,6 +3400,38 @@ export interface BetaToolBash20250124 {
3253
3400
  strict?: boolean;
3254
3401
  }
3255
3402
 
3403
+ /**
3404
+ * Reference to a single MCP tool by its server and remote name — the same
3405
+ * `server_name`/`name` pair `mcp_tool_use` carries.
3406
+ */
3407
+ export interface BetaToolChangeMCPToolReference {
3408
+ name: string;
3409
+
3410
+ server_name: string;
3411
+
3412
+ type: 'mcp_tool_reference';
3413
+ }
3414
+
3415
+ /**
3416
+ * Reference to every tool in the named MCP server's toolset.
3417
+ */
3418
+ export interface BetaToolChangeMCPToolsetReference {
3419
+ server_name: string;
3420
+
3421
+ type: 'mcp_toolset_reference';
3422
+ }
3423
+
3424
+ /**
3425
+ * Reference to a single tool the caller declared directly in `tools[]`. Does not
3426
+ * accept the composed `{server}_{name}` form the server assigns to MCP-resolved
3427
+ * tools — use `mcp_tool_reference` or `mcp_toolset_reference` for those.
3428
+ */
3429
+ export interface BetaToolChangeToolReference {
3430
+ name: string;
3431
+
3432
+ type: 'tool_reference';
3433
+ }
3434
+
3256
3435
  /**
3257
3436
  * How the model should use the provided tools. The model can use a specific tool,
3258
3437
  * any available tool, decide by itself, or not use tools at all.
@@ -3866,6 +4045,11 @@ export interface BetaUsage {
3866
4045
  */
3867
4046
  cache_read_input_tokens: number | null;
3868
4047
 
4048
+ /**
4049
+ * Outcome of the `fallback_credit_token` presented on this request.
4050
+ */
4051
+ fallback_credit: BetaFallbackCreditUsage | null;
4052
+
3869
4053
  /**
3870
4054
  * The geographic region where inference was performed for this request.
3871
4055
  */
@@ -4695,14 +4879,15 @@ export interface MessageCreateParamsBase {
4695
4879
  * When the appended-assistant form is used on a model that otherwise disallows
4696
4880
  * assistant-turn prefill, this token also authorizes that one prefill.
4697
4881
  */
4698
- fallback_credit_token?: string | null;
4882
+ fallback_credit_token?: string | BetaFallbackCreditTokenParam | null;
4699
4883
 
4700
4884
  /**
4701
4885
  * Body param: Opt-in server-side retry on one or more substitute models when the
4702
4886
  * requested model declines for policy reasons. Tried in order: if the first entry
4703
- * also declines, the second is tried, and so on.
4887
+ * also declines, the second is tried, and so on. The string "default" requests the
4888
+ * requested model's server-defined default fallback configuration.
4704
4889
  */
4705
- fallbacks?: Array<BetaFallbackParam> | null;
4890
+ fallbacks?: BetaFallbacksParam | null;
4706
4891
 
4707
4892
  /**
4708
4893
  * Body param: Specifies the geographic region for inference processing. If not
@@ -5307,11 +5492,16 @@ export declare namespace Messages {
5307
5492
  type BetaEncryptedCodeExecutionResultBlockParam as BetaEncryptedCodeExecutionResultBlockParam,
5308
5493
  type BetaFallbackBlock as BetaFallbackBlock,
5309
5494
  type BetaFallbackBlockParam as BetaFallbackBlockParam,
5495
+ type BetaFallbackCreditNotApplied as BetaFallbackCreditNotApplied,
5496
+ type BetaFallbackCreditRedeemed as BetaFallbackCreditRedeemed,
5497
+ type BetaFallbackCreditTokenParam as BetaFallbackCreditTokenParam,
5498
+ type BetaFallbackCreditUsage as BetaFallbackCreditUsage,
5310
5499
  type BetaFallbackInfo as BetaFallbackInfo,
5311
5500
  type BetaFallbackInfoParam as BetaFallbackInfoParam,
5312
5501
  type BetaFallbackMessageIterationUsage as BetaFallbackMessageIterationUsage,
5313
5502
  type BetaFallbackParam as BetaFallbackParam,
5314
5503
  type BetaFallbackRefusalTrigger as BetaFallbackRefusalTrigger,
5504
+ type BetaFallbacksParam as BetaFallbacksParam,
5315
5505
  type BetaFileDocumentSource as BetaFileDocumentSource,
5316
5506
  type BetaFileImageSource as BetaFileImageSource,
5317
5507
  type BetaImageBlockParam as BetaImageBlockParam,
@@ -5359,6 +5549,8 @@ export declare namespace Messages {
5359
5549
  type BetaRequestMCPServerToolConfiguration as BetaRequestMCPServerToolConfiguration,
5360
5550
  type BetaRequestMCPServerURLDefinition as BetaRequestMCPServerURLDefinition,
5361
5551
  type BetaRequestMCPToolResultBlockParam as BetaRequestMCPToolResultBlockParam,
5552
+ type BetaRequestToolAdditionBlock as BetaRequestToolAdditionBlock,
5553
+ type BetaRequestToolRemovalBlock as BetaRequestToolRemovalBlock,
5362
5554
  type BetaSearchResultBlockParam as BetaSearchResultBlockParam,
5363
5555
  type BetaServerToolCaller as BetaServerToolCaller,
5364
5556
  type BetaServerToolCaller20260120 as BetaServerToolCaller20260120,
@@ -5396,6 +5588,9 @@ export declare namespace Messages {
5396
5588
  type BetaTool as BetaTool,
5397
5589
  type BetaToolBash20241022 as BetaToolBash20241022,
5398
5590
  type BetaToolBash20250124 as BetaToolBash20250124,
5591
+ type BetaToolChangeMCPToolReference as BetaToolChangeMCPToolReference,
5592
+ type BetaToolChangeMCPToolsetReference as BetaToolChangeMCPToolsetReference,
5593
+ type BetaToolChangeToolReference as BetaToolChangeToolReference,
5399
5594
  type BetaToolChoice as BetaToolChoice,
5400
5595
  type BetaToolChoiceAny as BetaToolChoiceAny,
5401
5596
  type BetaToolChoiceAuto as BetaToolChoiceAuto,
@@ -1260,6 +1260,7 @@ export type Model =
1260
1260
  | 'claude-sonnet-5'
1261
1261
  | 'claude-fable-5'
1262
1262
  | 'claude-mythos-5'
1263
+ | 'claude-opus-5'
1263
1264
  | 'claude-opus-4-8'
1264
1265
  | 'claude-opus-4-7'
1265
1266
  | 'claude-mythos-preview'
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const VERSION = '0.114.0'; // x-release-please-version
1
+ export const VERSION = '0.115.0'; // x-release-please-version
package/version.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "0.114.0";
1
+ export declare const VERSION = "0.115.0";
2
2
  //# sourceMappingURL=version.d.mts.map
package/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "0.114.0";
1
+ export declare const VERSION = "0.115.0";
2
2
  //# sourceMappingURL=version.d.ts.map
package/version.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
- exports.VERSION = '0.114.0'; // x-release-please-version
4
+ exports.VERSION = '0.115.0'; // x-release-please-version
5
5
  //# sourceMappingURL=version.js.map
package/version.mjs CHANGED
@@ -1,2 +1,2 @@
1
- export const VERSION = '0.114.0'; // x-release-please-version
1
+ export const VERSION = '0.115.0'; // x-release-please-version
2
2
  //# sourceMappingURL=version.mjs.map
@@ -1,132 +0,0 @@
1
- import { BetaRunnableTool } from "./BetaRunnableTool.mjs";
2
- import { Anthropic } from "../../index.mjs";
3
- import { BetaMessage, BetaMessageParam, BetaToolUnion, MessageCreateParams } from "../../resources/beta.mjs";
4
- import { BetaMessageStream } from "../BetaMessageStream.mjs";
5
- /**
6
- * A ToolRunner handles the automatic conversation loop between the assistant and tools.
7
- *
8
- * A ToolRunner is an async iterable that yields either BetaMessage or BetaMessageStream objects
9
- * depending on the streaming configuration.
10
- */
11
- export declare class BetaToolRunner<Stream extends boolean> {
12
- #private;
13
- private client;
14
- constructor(client: Anthropic, params: BetaToolRunnerParams);
15
- [Symbol.asyncIterator](): AsyncIterator<Stream extends true ? BetaMessageStream : Stream extends false ? BetaMessage : BetaMessage | BetaMessageStream>;
16
- /**
17
- * Update the parameters for the next API call. This invalidates any cached tool responses.
18
- *
19
- * @param paramsOrMutator - Either new parameters or a function to mutate existing parameters
20
- *
21
- * @example
22
- * // Direct parameter update
23
- * runner.setMessagesParams({
24
- * model: 'claude-haiku-4-5',
25
- * max_tokens: 500,
26
- * });
27
- *
28
- * @example
29
- * // Using a mutator function
30
- * runner.setMessagesParams((params) => ({
31
- * ...params,
32
- * max_tokens: 100,
33
- * }));
34
- */
35
- setMessagesParams(params: BetaToolRunnerParams): void;
36
- setMessagesParams(mutator: (prevParams: BetaToolRunnerParams) => BetaToolRunnerParams): void;
37
- /**
38
- * Get the tool response for the last message from the assistant.
39
- * Avoids redundant tool executions by caching results.
40
- *
41
- * @returns A promise that resolves to a BetaMessageParam containing tool results, or null if no tools need to be executed
42
- *
43
- * @example
44
- * const toolResponse = await runner.generateToolResponse();
45
- * if (toolResponse) {
46
- * console.log('Tool results:', toolResponse.content);
47
- * }
48
- */
49
- generateToolResponse(): Promise<Anthropic.Beta.Messages.BetaMessageParam | null>;
50
- /**
51
- * Wait for the async iterator to complete. This works even if the async iterator hasn't yet started, and
52
- * will wait for an instance to start and go to completion.
53
- *
54
- * @returns A promise that resolves to the final BetaMessage when the iterator completes
55
- *
56
- * @example
57
- * // Start consuming the iterator
58
- * for await (const message of runner) {
59
- * console.log('Message:', message.content);
60
- * }
61
- *
62
- * // Meanwhile, wait for completion from another part of the code
63
- * const finalMessage = await runner.done();
64
- * console.log('Final response:', finalMessage.content);
65
- */
66
- done(): Promise<BetaMessage>;
67
- /**
68
- * Returns a promise indicating that the stream is done. Unlike .done(), this will eagerly read the stream:
69
- * * If the iterator has not been consumed, consume the entire iterator and return the final message from the
70
- * assistant.
71
- * * If the iterator has been consumed, waits for it to complete and returns the final message.
72
- *
73
- * @returns A promise that resolves to the final BetaMessage from the conversation
74
- * @throws {AnthropicError} If no messages were processed during the conversation
75
- *
76
- * @example
77
- * const finalMessage = await runner.runUntilDone();
78
- * console.log('Final response:', finalMessage.content);
79
- */
80
- runUntilDone(): Promise<BetaMessage>;
81
- /**
82
- * Get the current parameters being used by the ToolRunner.
83
- *
84
- * @returns A readonly view of the current ToolRunnerParams
85
- *
86
- * @example
87
- * const currentParams = runner.params;
88
- * console.log('Current model:', currentParams.model);
89
- * console.log('Message count:', currentParams.messages.length);
90
- */
91
- get params(): Readonly<BetaToolRunnerParams>;
92
- /**
93
- * Add one or more messages to the conversation history.
94
- *
95
- * @param messages - One or more BetaMessageParam objects to add to the conversation
96
- *
97
- * @example
98
- * runner.pushMessages(
99
- * { role: 'user', content: 'Also, what about the weather in NYC?' }
100
- * );
101
- *
102
- * @example
103
- * // Adding multiple messages
104
- * runner.pushMessages(
105
- * { role: 'user', content: 'What about NYC?' },
106
- * { role: 'user', content: 'And Boston?' }
107
- * );
108
- */
109
- pushMessages(...messages: BetaMessageParam[]): void;
110
- /**
111
- * Makes the ToolRunner directly awaitable, equivalent to calling .runUntilDone()
112
- * This allows using `await runner` instead of `await runner.runUntilDone()`
113
- */
114
- then<TResult1 = BetaMessage, TResult2 = never>(onfulfilled?: ((value: BetaMessage) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): Promise<TResult1 | TResult2>;
115
- }
116
- type Simplify<T> = {
117
- [KeyType in keyof T]: T[KeyType];
118
- } & {};
119
- /**
120
- * Parameters for creating a ToolRunner, extending MessageCreateParams with runnable tools.
121
- */
122
- export type BetaToolRunnerParams = Simplify<Omit<MessageCreateParams, 'tools'> & {
123
- tools: (BetaToolUnion | BetaRunnableTool<any>)[];
124
- /**
125
- * Maximum number of iterations (API requests) to make in the tool execution loop.
126
- * Each iteration consists of: assistant response → tool execution → tool results.
127
- * When exceeded, the loop will terminate even if tools are still being requested.
128
- */
129
- max_iterations?: number;
130
- }>;
131
- export {};
132
- //# sourceMappingURL=ToolRunner.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ToolRunner.d.mts","sourceRoot":"","sources":["../../src/lib/tools/ToolRunner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,+BAA2B;AAEtD,OAAO,EAAE,SAAS,EAAE,wBAAc;AAElC,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,aAAa,EAAE,mBAAmB,EAAE,iCAA6B;AACzG,OAAO,EAAE,iBAAiB,EAAE,iCAA6B;AAmBzD;;;;;GAKG;AACH,qBAAa,cAAc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CAAC,CAAC,OAAO,CAAC;CAAE,GAAG,EAAE,CAAC;AAE7D;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,QAAQ,CACzC,IAAI,CAAC,mBAAmB,EAAE,OAAO,CAAC,GAAG;IACnC,KAAK,EAAE,CAAC,aAAa,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;IACjD;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CACF,CAAC"}
@@ -1,132 +0,0 @@
1
- import { BetaRunnableTool } from "./BetaRunnableTool.js";
2
- import { Anthropic } from "../../index.js";
3
- import { BetaMessage, BetaMessageParam, BetaToolUnion, MessageCreateParams } from "../../resources/beta.js";
4
- import { BetaMessageStream } from "../BetaMessageStream.js";
5
- /**
6
- * A ToolRunner handles the automatic conversation loop between the assistant and tools.
7
- *
8
- * A ToolRunner is an async iterable that yields either BetaMessage or BetaMessageStream objects
9
- * depending on the streaming configuration.
10
- */
11
- export declare class BetaToolRunner<Stream extends boolean> {
12
- #private;
13
- private client;
14
- constructor(client: Anthropic, params: BetaToolRunnerParams);
15
- [Symbol.asyncIterator](): AsyncIterator<Stream extends true ? BetaMessageStream : Stream extends false ? BetaMessage : BetaMessage | BetaMessageStream>;
16
- /**
17
- * Update the parameters for the next API call. This invalidates any cached tool responses.
18
- *
19
- * @param paramsOrMutator - Either new parameters or a function to mutate existing parameters
20
- *
21
- * @example
22
- * // Direct parameter update
23
- * runner.setMessagesParams({
24
- * model: 'claude-haiku-4-5',
25
- * max_tokens: 500,
26
- * });
27
- *
28
- * @example
29
- * // Using a mutator function
30
- * runner.setMessagesParams((params) => ({
31
- * ...params,
32
- * max_tokens: 100,
33
- * }));
34
- */
35
- setMessagesParams(params: BetaToolRunnerParams): void;
36
- setMessagesParams(mutator: (prevParams: BetaToolRunnerParams) => BetaToolRunnerParams): void;
37
- /**
38
- * Get the tool response for the last message from the assistant.
39
- * Avoids redundant tool executions by caching results.
40
- *
41
- * @returns A promise that resolves to a BetaMessageParam containing tool results, or null if no tools need to be executed
42
- *
43
- * @example
44
- * const toolResponse = await runner.generateToolResponse();
45
- * if (toolResponse) {
46
- * console.log('Tool results:', toolResponse.content);
47
- * }
48
- */
49
- generateToolResponse(): Promise<Anthropic.Beta.Messages.BetaMessageParam | null>;
50
- /**
51
- * Wait for the async iterator to complete. This works even if the async iterator hasn't yet started, and
52
- * will wait for an instance to start and go to completion.
53
- *
54
- * @returns A promise that resolves to the final BetaMessage when the iterator completes
55
- *
56
- * @example
57
- * // Start consuming the iterator
58
- * for await (const message of runner) {
59
- * console.log('Message:', message.content);
60
- * }
61
- *
62
- * // Meanwhile, wait for completion from another part of the code
63
- * const finalMessage = await runner.done();
64
- * console.log('Final response:', finalMessage.content);
65
- */
66
- done(): Promise<BetaMessage>;
67
- /**
68
- * Returns a promise indicating that the stream is done. Unlike .done(), this will eagerly read the stream:
69
- * * If the iterator has not been consumed, consume the entire iterator and return the final message from the
70
- * assistant.
71
- * * If the iterator has been consumed, waits for it to complete and returns the final message.
72
- *
73
- * @returns A promise that resolves to the final BetaMessage from the conversation
74
- * @throws {AnthropicError} If no messages were processed during the conversation
75
- *
76
- * @example
77
- * const finalMessage = await runner.runUntilDone();
78
- * console.log('Final response:', finalMessage.content);
79
- */
80
- runUntilDone(): Promise<BetaMessage>;
81
- /**
82
- * Get the current parameters being used by the ToolRunner.
83
- *
84
- * @returns A readonly view of the current ToolRunnerParams
85
- *
86
- * @example
87
- * const currentParams = runner.params;
88
- * console.log('Current model:', currentParams.model);
89
- * console.log('Message count:', currentParams.messages.length);
90
- */
91
- get params(): Readonly<BetaToolRunnerParams>;
92
- /**
93
- * Add one or more messages to the conversation history.
94
- *
95
- * @param messages - One or more BetaMessageParam objects to add to the conversation
96
- *
97
- * @example
98
- * runner.pushMessages(
99
- * { role: 'user', content: 'Also, what about the weather in NYC?' }
100
- * );
101
- *
102
- * @example
103
- * // Adding multiple messages
104
- * runner.pushMessages(
105
- * { role: 'user', content: 'What about NYC?' },
106
- * { role: 'user', content: 'And Boston?' }
107
- * );
108
- */
109
- pushMessages(...messages: BetaMessageParam[]): void;
110
- /**
111
- * Makes the ToolRunner directly awaitable, equivalent to calling .runUntilDone()
112
- * This allows using `await runner` instead of `await runner.runUntilDone()`
113
- */
114
- then<TResult1 = BetaMessage, TResult2 = never>(onfulfilled?: ((value: BetaMessage) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): Promise<TResult1 | TResult2>;
115
- }
116
- type Simplify<T> = {
117
- [KeyType in keyof T]: T[KeyType];
118
- } & {};
119
- /**
120
- * Parameters for creating a ToolRunner, extending MessageCreateParams with runnable tools.
121
- */
122
- export type BetaToolRunnerParams = Simplify<Omit<MessageCreateParams, 'tools'> & {
123
- tools: (BetaToolUnion | BetaRunnableTool<any>)[];
124
- /**
125
- * Maximum number of iterations (API requests) to make in the tool execution loop.
126
- * Each iteration consists of: assistant response → tool execution → tool results.
127
- * When exceeded, the loop will terminate even if tools are still being requested.
128
- */
129
- max_iterations?: number;
130
- }>;
131
- export {};
132
- //# sourceMappingURL=ToolRunner.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ToolRunner.d.ts","sourceRoot":"","sources":["../../src/lib/tools/ToolRunner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,8BAA2B;AAEtD,OAAO,EAAE,SAAS,EAAE,uBAAc;AAElC,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,aAAa,EAAE,mBAAmB,EAAE,gCAA6B;AACzG,OAAO,EAAE,iBAAiB,EAAE,gCAA6B;AAmBzD;;;;;GAKG;AACH,qBAAa,cAAc,CAAC,MAAM,SAAS,OAAO;;IAqB9C,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,SAAS,EACzB,MAAM,EAAE,oBAAoB;IAevB,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,aAAa,CAC5C,MAAM,SA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