@anthropic-ai/sdk 0.106.0 → 0.108.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 (121) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/README.md +16 -1
  3. package/client.d.mts +2 -2
  4. package/client.d.mts.map +1 -1
  5. package/client.d.ts +2 -2
  6. package/client.d.ts.map +1 -1
  7. package/client.js.map +1 -1
  8. package/client.mjs.map +1 -1
  9. package/package.json +1 -1
  10. package/resources/beta/agents/agents.d.mts +1 -1
  11. package/resources/beta/agents/agents.d.mts.map +1 -1
  12. package/resources/beta/agents/agents.d.ts +1 -1
  13. package/resources/beta/agents/agents.d.ts.map +1 -1
  14. package/resources/beta/agents/agents.js.map +1 -1
  15. package/resources/beta/agents/agents.mjs.map +1 -1
  16. package/resources/beta/beta.d.mts +2 -2
  17. package/resources/beta/beta.d.mts.map +1 -1
  18. package/resources/beta/beta.d.ts +2 -2
  19. package/resources/beta/beta.d.ts.map +1 -1
  20. package/resources/beta/beta.js.map +1 -1
  21. package/resources/beta/beta.mjs.map +1 -1
  22. package/resources/beta/deployments.d.mts +18 -6
  23. package/resources/beta/deployments.d.mts.map +1 -1
  24. package/resources/beta/deployments.d.ts +18 -6
  25. package/resources/beta/deployments.d.ts.map +1 -1
  26. package/resources/beta/deployments.js +18 -6
  27. package/resources/beta/deployments.js.map +1 -1
  28. package/resources/beta/deployments.mjs +18 -6
  29. package/resources/beta/deployments.mjs.map +1 -1
  30. package/resources/beta/index.d.mts +1 -1
  31. package/resources/beta/index.d.mts.map +1 -1
  32. package/resources/beta/index.d.ts +1 -1
  33. package/resources/beta/index.d.ts.map +1 -1
  34. package/resources/beta/index.js.map +1 -1
  35. package/resources/beta/index.mjs.map +1 -1
  36. package/resources/beta/messages/batches.d.mts +29 -21
  37. package/resources/beta/messages/batches.d.mts.map +1 -1
  38. package/resources/beta/messages/batches.d.ts +29 -21
  39. package/resources/beta/messages/batches.d.ts.map +1 -1
  40. package/resources/beta/messages/batches.js +6 -6
  41. package/resources/beta/messages/batches.mjs +6 -6
  42. package/resources/beta/messages/index.d.mts +1 -1
  43. package/resources/beta/messages/index.d.mts.map +1 -1
  44. package/resources/beta/messages/index.d.ts +1 -1
  45. package/resources/beta/messages/index.d.ts.map +1 -1
  46. package/resources/beta/messages/index.js.map +1 -1
  47. package/resources/beta/messages/index.mjs.map +1 -1
  48. package/resources/beta/messages/messages.d.mts +160 -32
  49. package/resources/beta/messages/messages.d.mts.map +1 -1
  50. package/resources/beta/messages/messages.d.ts +160 -32
  51. package/resources/beta/messages/messages.d.ts.map +1 -1
  52. package/resources/beta/messages/messages.js +6 -3
  53. package/resources/beta/messages/messages.js.map +1 -1
  54. package/resources/beta/messages/messages.mjs +6 -3
  55. package/resources/beta/messages/messages.mjs.map +1 -1
  56. package/resources/completions.d.mts +12 -7
  57. package/resources/completions.d.mts.map +1 -1
  58. package/resources/completions.d.ts +12 -7
  59. package/resources/completions.d.ts.map +1 -1
  60. package/resources/index.d.mts +1 -1
  61. package/resources/index.d.mts.map +1 -1
  62. package/resources/index.d.ts +1 -1
  63. package/resources/index.d.ts.map +1 -1
  64. package/resources/index.js.map +1 -1
  65. package/resources/index.mjs.map +1 -1
  66. package/resources/messages/batches.d.mts +8 -7
  67. package/resources/messages/batches.d.mts.map +1 -1
  68. package/resources/messages/batches.d.ts +8 -7
  69. package/resources/messages/batches.d.ts.map +1 -1
  70. package/resources/messages/batches.js +6 -6
  71. package/resources/messages/batches.mjs +6 -6
  72. package/resources/messages/index.d.mts +1 -1
  73. package/resources/messages/index.d.mts.map +1 -1
  74. package/resources/messages/index.d.ts +1 -1
  75. package/resources/messages/index.d.ts.map +1 -1
  76. package/resources/messages/index.js.map +1 -1
  77. package/resources/messages/index.mjs.map +1 -1
  78. package/resources/messages/messages.d.mts +173 -44
  79. package/resources/messages/messages.d.mts.map +1 -1
  80. package/resources/messages/messages.d.ts +173 -44
  81. package/resources/messages/messages.d.ts.map +1 -1
  82. package/resources/messages/messages.js +11 -3
  83. package/resources/messages/messages.js.map +1 -1
  84. package/resources/messages/messages.mjs +11 -3
  85. package/resources/messages/messages.mjs.map +1 -1
  86. package/src/client.ts +4 -0
  87. package/src/resources/beta/agents/agents.ts +1 -0
  88. package/src/resources/beta/beta.ts +4 -0
  89. package/src/resources/beta/deployments.ts +18 -6
  90. package/src/resources/beta/index.ts +2 -0
  91. package/src/resources/beta/messages/batches.ts +29 -21
  92. package/src/resources/beta/messages/index.ts +2 -0
  93. package/src/resources/beta/messages/messages.ts +197 -31
  94. package/src/resources/completions.ts +12 -7
  95. package/src/resources/index.ts +2 -0
  96. package/src/resources/messages/batches.ts +8 -7
  97. package/src/resources/messages/index.ts +2 -0
  98. package/src/resources/messages/messages.ts +214 -41
  99. package/src/tools/agent-toolset/fs-util.ts +12 -12
  100. package/src/tools/agent-toolset/node.ts +29 -12
  101. package/src/version.ts +1 -1
  102. package/tools/agent-toolset/fs-util.d.mts +4 -3
  103. package/tools/agent-toolset/fs-util.d.mts.map +1 -1
  104. package/tools/agent-toolset/fs-util.d.ts +4 -3
  105. package/tools/agent-toolset/fs-util.d.ts.map +1 -1
  106. package/tools/agent-toolset/fs-util.js +12 -12
  107. package/tools/agent-toolset/fs-util.js.map +1 -1
  108. package/tools/agent-toolset/fs-util.mjs +12 -12
  109. package/tools/agent-toolset/fs-util.mjs.map +1 -1
  110. package/tools/agent-toolset/node.d.mts +10 -9
  111. package/tools/agent-toolset/node.d.mts.map +1 -1
  112. package/tools/agent-toolset/node.d.ts +10 -9
  113. package/tools/agent-toolset/node.d.ts.map +1 -1
  114. package/tools/agent-toolset/node.js +29 -10
  115. package/tools/agent-toolset/node.js.map +1 -1
  116. package/tools/agent-toolset/node.mjs +29 -10
  117. package/tools/agent-toolset/node.mjs.map +1 -1
  118. package/version.d.mts +1 -1
  119. package/version.d.ts +1 -1
  120. package/version.js +1 -1
  121. package/version.mjs +1 -1
@@ -44,7 +44,7 @@ export class Messages extends APIResource {
44
44
  * conversations.
45
45
  *
46
46
  * Learn more about the Messages API in our
47
- * [user guide](https://docs.claude.com/en/docs/initial-setup)
47
+ * [user guide](https://platform.claude.com/docs/en/get-started)
48
48
  *
49
49
  * @example
50
50
  * ```ts
@@ -174,7 +174,7 @@ export class Messages extends APIResource {
174
174
  * including tools, images, and documents, without creating it.
175
175
  *
176
176
  * Learn more about token counting in our
177
- * [user guide](https://docs.claude.com/en/docs/build-with-claude/token-counting)
177
+ * [user guide](https://platform.claude.com/docs/en/build-with-claude/token-counting)
178
178
  *
179
179
  * @example
180
180
  * ```ts
@@ -185,8 +185,16 @@ export class Messages extends APIResource {
185
185
  * });
186
186
  * ```
187
187
  */
188
- countTokens(body: MessageCountTokensParams, options?: RequestOptions): APIPromise<MessageTokensCount> {
189
- return this._client.post('/v1/messages/count_tokens', { body, ...options });
188
+ countTokens(params: MessageCountTokensParams, options?: RequestOptions): APIPromise<MessageTokensCount> {
189
+ const { user_profile_id, ...body } = params;
190
+ return this._client.post('/v1/messages/count_tokens', {
191
+ body,
192
+ ...options,
193
+ headers: buildHeaders([
194
+ { ...(user_profile_id != null ? { 'anthropic-user-profile-id': user_profile_id } : undefined) },
195
+ options?.headers,
196
+ ]),
197
+ });
190
198
  }
191
199
  }
192
200
 
@@ -294,7 +302,7 @@ export interface CacheControlEphemeral {
294
302
  * - `1h`: 1 hour
295
303
  *
296
304
  * Defaults to `5m`. See
297
- * [prompt caching pricing](https://docs.claude.com/en/docs/build-with-claude/prompt-caching)
305
+ * [prompt caching pricing](https://platform.claude.com/docs/en/build-with-claude/prompt-caching)
298
306
  * for details.
299
307
  */
300
308
  ttl?: '5m' | '1h';
@@ -1153,6 +1161,8 @@ export type MessageCountTokensTool =
1153
1161
  | WebSearchTool20260209
1154
1162
  | WebFetchTool20260209
1155
1163
  | WebFetchTool20260309
1164
+ | WebSearchTool20260318
1165
+ | WebFetchTool20260318
1156
1166
  | ToolSearchToolBm25_20251119
1157
1167
  | ToolSearchToolRegex20251119;
1158
1168
 
@@ -1246,6 +1256,7 @@ export interface MidConversationSystemBlockParam {
1246
1256
  * details and options.
1247
1257
  */
1248
1258
  export type Model =
1259
+ | 'claude-sonnet-5'
1249
1260
  | 'claude-fable-5'
1250
1261
  | 'claude-mythos-5'
1251
1262
  | 'claude-opus-4-8'
@@ -1772,7 +1783,7 @@ export interface ThinkingConfigEnabled {
1772
1783
  * Must be ≥1024 and less than `max_tokens`.
1773
1784
  *
1774
1785
  * See
1775
- * [extended thinking](https://docs.claude.com/en/docs/build-with-claude/extended-thinking)
1786
+ * [extended thinking](https://platform.claude.com/docs/en/build-with-claude/extended-thinking)
1776
1787
  * for details.
1777
1788
  */
1778
1789
  budget_tokens: number;
@@ -1796,7 +1807,7 @@ export interface ThinkingConfigEnabled {
1796
1807
  * tokens and counts towards your `max_tokens` limit.
1797
1808
  *
1798
1809
  * See
1799
- * [extended thinking](https://docs.claude.com/en/docs/build-with-claude/extended-thinking)
1810
+ * [extended thinking](https://platform.claude.com/docs/en/build-with-claude/extended-thinking)
1800
1811
  * for details.
1801
1812
  */
1802
1813
  export type ThinkingConfigParam = ThinkingConfigEnabled | ThinkingConfigDisabled | ThinkingConfigAdaptive;
@@ -2266,6 +2277,8 @@ export type ToolUnion =
2266
2277
  | WebSearchTool20260209
2267
2278
  | WebFetchTool20260209
2268
2279
  | WebFetchTool20260309
2280
+ | WebSearchTool20260318
2281
+ | WebFetchTool20260318
2269
2282
  | ToolSearchToolBm25_20251119
2270
2283
  | ToolSearchToolRegex20251119;
2271
2284
 
@@ -2610,6 +2623,81 @@ export interface WebFetchTool20260309 {
2610
2623
  use_cache?: boolean;
2611
2624
  }
2612
2625
 
2626
+ export interface WebFetchTool20260318 {
2627
+ /**
2628
+ * Name of the tool.
2629
+ *
2630
+ * This is how the tool will be called by the model and in `tool_use` blocks.
2631
+ */
2632
+ name: 'web_fetch';
2633
+
2634
+ type: 'web_fetch_20260318';
2635
+
2636
+ allowed_callers?: Array<
2637
+ 'direct' | 'code_execution_20250825' | 'code_execution_20260120' | 'code_execution_20260521'
2638
+ >;
2639
+
2640
+ /**
2641
+ * List of domains to allow fetching from
2642
+ */
2643
+ allowed_domains?: Array<string> | null;
2644
+
2645
+ /**
2646
+ * List of domains to block fetching from
2647
+ */
2648
+ blocked_domains?: Array<string> | null;
2649
+
2650
+ /**
2651
+ * Create a cache control breakpoint at this content block.
2652
+ */
2653
+ cache_control?: CacheControlEphemeral | null;
2654
+
2655
+ /**
2656
+ * Citations configuration for fetched documents. Citations are disabled by
2657
+ * default.
2658
+ */
2659
+ citations?: CitationsConfigParam | null;
2660
+
2661
+ /**
2662
+ * If true, tool will not be included in initial system prompt. Only loaded when
2663
+ * returned via tool_reference from tool search.
2664
+ */
2665
+ defer_loading?: boolean;
2666
+
2667
+ /**
2668
+ * Maximum number of tokens used by including web page text content in the context.
2669
+ * The limit is approximate and does not apply to binary content such as PDFs.
2670
+ */
2671
+ max_content_tokens?: number | null;
2672
+
2673
+ /**
2674
+ * Maximum number of times the tool can be used in the API request.
2675
+ */
2676
+ max_uses?: number | null;
2677
+
2678
+ /**
2679
+ * How this tool's result blocks appear in the API response when the result was
2680
+ * consumed by a completed code_execution call in the same turn. 'full' returns the
2681
+ * complete content (default). 'excluded' drops the nested server_tool_use and
2682
+ * result block pair entirely. Results from direct calls, or from code_execution
2683
+ * calls that paused before completing, are always returned in full so they can be
2684
+ * sent back on the next turn.
2685
+ */
2686
+ response_inclusion?: 'full' | 'excluded';
2687
+
2688
+ /**
2689
+ * When true, guarantees schema validation on tool names and inputs
2690
+ */
2691
+ strict?: boolean;
2692
+
2693
+ /**
2694
+ * Whether to use cached content. Set to false to bypass the cache and fetch fresh
2695
+ * content. Only set to false when the user explicitly requests fresh content or
2696
+ * when fetching rapidly-changing sources.
2697
+ */
2698
+ use_cache?: boolean;
2699
+ }
2700
+
2613
2701
  export interface WebFetchToolResultBlock {
2614
2702
  /**
2615
2703
  * Tool invocation directly from the model.
@@ -2814,6 +2902,70 @@ export namespace WebSearchTool20260209 {
2814
2902
  export type UserLocation = Messages.UserLocation;
2815
2903
  }
2816
2904
 
2905
+ export interface WebSearchTool20260318 {
2906
+ /**
2907
+ * Name of the tool.
2908
+ *
2909
+ * This is how the tool will be called by the model and in `tool_use` blocks.
2910
+ */
2911
+ name: 'web_search';
2912
+
2913
+ type: 'web_search_20260318';
2914
+
2915
+ allowed_callers?: Array<
2916
+ 'direct' | 'code_execution_20250825' | 'code_execution_20260120' | 'code_execution_20260521'
2917
+ >;
2918
+
2919
+ /**
2920
+ * If provided, only these domains will be included in results. Cannot be used
2921
+ * alongside `blocked_domains`.
2922
+ */
2923
+ allowed_domains?: Array<string> | null;
2924
+
2925
+ /**
2926
+ * If provided, these domains will never appear in results. Cannot be used
2927
+ * alongside `allowed_domains`.
2928
+ */
2929
+ blocked_domains?: Array<string> | null;
2930
+
2931
+ /**
2932
+ * Create a cache control breakpoint at this content block.
2933
+ */
2934
+ cache_control?: CacheControlEphemeral | null;
2935
+
2936
+ /**
2937
+ * If true, tool will not be included in initial system prompt. Only loaded when
2938
+ * returned via tool_reference from tool search.
2939
+ */
2940
+ defer_loading?: boolean;
2941
+
2942
+ /**
2943
+ * Maximum number of times the tool can be used in the API request.
2944
+ */
2945
+ max_uses?: number | null;
2946
+
2947
+ /**
2948
+ * How this tool's result blocks appear in the API response when the result was
2949
+ * consumed by a completed code_execution call in the same turn. 'full' returns the
2950
+ * complete content (default). 'excluded' drops the nested server_tool_use and
2951
+ * result block pair entirely. Results from direct calls, or from code_execution
2952
+ * calls that paused before completing, are always returned in full so they can be
2953
+ * sent back on the next turn.
2954
+ */
2955
+ response_inclusion?: 'full' | 'excluded';
2956
+
2957
+ /**
2958
+ * When true, guarantees schema validation on tool names and inputs
2959
+ */
2960
+ strict?: boolean;
2961
+
2962
+ /**
2963
+ * Parameters for the user's location. Used to provide more relevant search
2964
+ * results.
2965
+ */
2966
+ user_location?: UserLocation | null;
2967
+ }
2968
+
2817
2969
  export interface WebSearchToolRequestError {
2818
2970
  error_code: WebSearchToolResultErrorCode;
2819
2971
 
@@ -2895,11 +3047,12 @@ export interface MessageCreateParamsBase {
2895
3047
  * only specifies the absolute maximum number of tokens to generate.
2896
3048
  *
2897
3049
  * Set to `0` to populate the
2898
- * [prompt cache](https://docs.claude.com/en/docs/build-with-claude/prompt-caching#pre-warming-the-cache)
3050
+ * [prompt cache](https://platform.claude.com/docs/en/build-with-claude/prompt-caching#pre-warming-the-cache)
2899
3051
  * without generating a response.
2900
3052
  *
2901
3053
  * Different models have different maximum values for this parameter. See
2902
- * [models](https://docs.claude.com/en/docs/models-overview) for details.
3054
+ * [models](https://platform.claude.com/docs/en/about-claude/models/overview) for
3055
+ * details.
2903
3056
  */
2904
3057
  max_tokens: number;
2905
3058
 
@@ -2961,12 +3114,13 @@ export interface MessageCreateParamsBase {
2961
3114
  * { "role": "user", "content": [{ "type": "text", "text": "Hello, Claude" }] }
2962
3115
  * ```
2963
3116
  *
2964
- * See [input examples](https://docs.claude.com/en/api/messages-examples).
3117
+ * See
3118
+ * [input examples](https://platform.claude.com/docs/en/build-with-claude/working-with-messages).
2965
3119
  *
2966
3120
  * Note that if you want to include a
2967
- * [system prompt](https://docs.claude.com/en/docs/system-prompts), you can use the
2968
- * top-level `system` parameter — there is no `"system"` role for input messages in
2969
- * the Messages API.
3121
+ * [system prompt](https://platform.claude.com/docs/en/build-with-claude/prompt-engineering/claude-prompting-best-practices#give-claude-a-role),
3122
+ * you can use the top-level `system` parameter — there is no `"system"` role for
3123
+ * input messages in the Messages API.
2970
3124
  *
2971
3125
  * There is a limit of 100,000 messages in a single request.
2972
3126
  */
@@ -3013,7 +3167,8 @@ export interface MessageCreateParamsBase {
3013
3167
  * standard capacity for this request.
3014
3168
  *
3015
3169
  * Anthropic offers different levels of service for your API requests. See
3016
- * [service-tiers](https://docs.claude.com/en/api/service-tiers) for details.
3170
+ * [service-tiers](https://platform.claude.com/docs/en/api/service-tiers) for
3171
+ * details.
3017
3172
  */
3018
3173
  service_tier?: 'auto' | 'standard_only';
3019
3174
 
@@ -3034,7 +3189,8 @@ export interface MessageCreateParamsBase {
3034
3189
  * Body param: Whether to incrementally stream the response using server-sent
3035
3190
  * events.
3036
3191
  *
3037
- * See [streaming](https://docs.claude.com/en/api/messages-streaming) for details.
3192
+ * See [streaming](https://platform.claude.com/docs/en/build-with-claude/streaming)
3193
+ * for details.
3038
3194
  */
3039
3195
  stream?: boolean;
3040
3196
 
@@ -3043,7 +3199,7 @@ export interface MessageCreateParamsBase {
3043
3199
  *
3044
3200
  * A system prompt is a way of providing context and instructions to Claude, such
3045
3201
  * as specifying a particular goal or role. See our
3046
- * [guide to system prompts](https://docs.claude.com/en/docs/system-prompts).
3202
+ * [guide to system prompts](https://platform.claude.com/docs/en/build-with-claude/prompt-engineering/claude-prompting-best-practices#give-claude-a-role).
3047
3203
  */
3048
3204
  system?: string | Array<TextBlockParam>;
3049
3205
 
@@ -3062,7 +3218,7 @@ export interface MessageCreateParamsBase {
3062
3218
  * tokens and counts towards your `max_tokens` limit.
3063
3219
  *
3064
3220
  * See
3065
- * [extended thinking](https://docs.claude.com/en/docs/build-with-claude/extended-thinking)
3221
+ * [extended thinking](https://platform.claude.com/docs/en/build-with-claude/extended-thinking)
3066
3222
  * for details.
3067
3223
  */
3068
3224
  thinking?: ThinkingConfigParam;
@@ -3083,9 +3239,9 @@ export interface MessageCreateParamsBase {
3083
3239
  *
3084
3240
  * There are two types of tools: **client tools** and **server tools**. The
3085
3241
  * behavior described below applies to client tools. For
3086
- * [server tools](https://docs.claude.com/en/docs/agents-and-tools/tool-use/overview#server-tools),
3242
+ * [server tools](https://platform.claude.com/docs/en/agents-and-tools/tool-use/server-tools),
3087
3243
  * see their individual documentation as each has its own behavior (e.g., the
3088
- * [web search tool](https://docs.claude.com/en/docs/agents-and-tools/tool-use/web-search-tool)).
3244
+ * [web search tool](https://platform.claude.com/docs/en/agents-and-tools/tool-use/web-search-tool)).
3089
3245
  *
3090
3246
  * Each tool definition includes:
3091
3247
  *
@@ -3148,7 +3304,9 @@ export interface MessageCreateParamsBase {
3148
3304
  * functions, or more generally whenever you want the model to produce a particular
3149
3305
  * JSON structure of output.
3150
3306
  *
3151
- * See our [guide](https://docs.claude.com/en/docs/tool-use) for more details.
3307
+ * See our
3308
+ * [guide](https://platform.claude.com/docs/en/agents-and-tools/tool-use/overview)
3309
+ * for more details.
3152
3310
  */
3153
3311
  tools?: Array<ToolUnion>;
3154
3312
 
@@ -3183,7 +3341,8 @@ export interface MessageCreateParamsNonStreaming extends MessageCreateParamsBase
3183
3341
  * Body param: Whether to incrementally stream the response using server-sent
3184
3342
  * events.
3185
3343
  *
3186
- * See [streaming](https://docs.claude.com/en/api/messages-streaming) for details.
3344
+ * See [streaming](https://platform.claude.com/docs/en/build-with-claude/streaming)
3345
+ * for details.
3187
3346
  */
3188
3347
  stream?: false;
3189
3348
  }
@@ -3193,7 +3352,8 @@ export interface MessageCreateParamsStreaming extends MessageCreateParamsBase {
3193
3352
  * Body param: Whether to incrementally stream the response using server-sent
3194
3353
  * events.
3195
3354
  *
3196
- * See [streaming](https://docs.claude.com/en/api/messages-streaming) for details.
3355
+ * See [streaming](https://platform.claude.com/docs/en/build-with-claude/streaming)
3356
+ * for details.
3197
3357
  */
3198
3358
  stream: true;
3199
3359
  }
@@ -3202,7 +3362,7 @@ export type MessageStreamParams = ParseableMessageCreateParams;
3202
3362
 
3203
3363
  export interface MessageCountTokensParams {
3204
3364
  /**
3205
- * Input messages.
3365
+ * Body param: Input messages.
3206
3366
  *
3207
3367
  * Our models are trained to operate on alternating `user` and `assistant`
3208
3368
  * conversational turns. When creating a new `Message`, you specify the prior
@@ -3259,19 +3419,20 @@ export interface MessageCountTokensParams {
3259
3419
  * { "role": "user", "content": [{ "type": "text", "text": "Hello, Claude" }] }
3260
3420
  * ```
3261
3421
  *
3262
- * See [input examples](https://docs.claude.com/en/api/messages-examples).
3422
+ * See
3423
+ * [input examples](https://platform.claude.com/docs/en/build-with-claude/working-with-messages).
3263
3424
  *
3264
3425
  * Note that if you want to include a
3265
- * [system prompt](https://docs.claude.com/en/docs/system-prompts), you can use the
3266
- * top-level `system` parameter — there is no `"system"` role for input messages in
3267
- * the Messages API.
3426
+ * [system prompt](https://platform.claude.com/docs/en/build-with-claude/prompt-engineering/claude-prompting-best-practices#give-claude-a-role),
3427
+ * you can use the top-level `system` parameter — there is no `"system"` role for
3428
+ * input messages in the Messages API.
3268
3429
  *
3269
3430
  * There is a limit of 100,000 messages in a single request.
3270
3431
  */
3271
3432
  messages: Array<MessageParam>;
3272
3433
 
3273
3434
  /**
3274
- * The model that will complete your prompt.
3435
+ * Body param: The model that will complete your prompt.
3275
3436
  *
3276
3437
  * See [models](https://docs.anthropic.com/en/docs/models-overview) for additional
3277
3438
  * details and options.
@@ -3279,46 +3440,47 @@ export interface MessageCountTokensParams {
3279
3440
  model: Model;
3280
3441
 
3281
3442
  /**
3282
- * Top-level cache control automatically applies a cache_control marker to the last
3283
- * cacheable block in the request.
3443
+ * Body param: Top-level cache control automatically applies a cache_control marker
3444
+ * to the last cacheable block in the request.
3284
3445
  */
3285
3446
  cache_control?: CacheControlEphemeral | null;
3286
3447
 
3287
3448
  /**
3288
- * Configuration options for the model's output, such as the output format.
3449
+ * Body param: Configuration options for the model's output, such as the output
3450
+ * format.
3289
3451
  */
3290
3452
  output_config?: OutputConfig;
3291
3453
 
3292
3454
  /**
3293
- * System prompt.
3455
+ * Body param: System prompt.
3294
3456
  *
3295
3457
  * A system prompt is a way of providing context and instructions to Claude, such
3296
3458
  * as specifying a particular goal or role. See our
3297
- * [guide to system prompts](https://docs.claude.com/en/docs/system-prompts).
3459
+ * [guide to system prompts](https://platform.claude.com/docs/en/build-with-claude/prompt-engineering/claude-prompting-best-practices#give-claude-a-role).
3298
3460
  */
3299
3461
  system?: string | Array<TextBlockParam>;
3300
3462
 
3301
3463
  /**
3302
- * Configuration for enabling Claude's extended thinking.
3464
+ * Body param: Configuration for enabling Claude's extended thinking.
3303
3465
  *
3304
3466
  * When enabled, responses include `thinking` content blocks showing Claude's
3305
3467
  * thinking process before the final answer. Requires a minimum budget of 1,024
3306
3468
  * tokens and counts towards your `max_tokens` limit.
3307
3469
  *
3308
3470
  * See
3309
- * [extended thinking](https://docs.claude.com/en/docs/build-with-claude/extended-thinking)
3471
+ * [extended thinking](https://platform.claude.com/docs/en/build-with-claude/extended-thinking)
3310
3472
  * for details.
3311
3473
  */
3312
3474
  thinking?: ThinkingConfigParam;
3313
3475
 
3314
3476
  /**
3315
- * How the model should use the provided tools. The model can use a specific tool,
3316
- * any available tool, decide by itself, or not use tools at all.
3477
+ * Body param: How the model should use the provided tools. The model can use a
3478
+ * specific tool, any available tool, decide by itself, or not use tools at all.
3317
3479
  */
3318
3480
  tool_choice?: ToolChoice;
3319
3481
 
3320
3482
  /**
3321
- * Definitions of tools that the model may use.
3483
+ * Body param: Definitions of tools that the model may use.
3322
3484
  *
3323
3485
  * If you include `tools` in your API request, the model may return `tool_use`
3324
3486
  * content blocks that represent the model's use of those tools. You can then run
@@ -3327,9 +3489,9 @@ export interface MessageCountTokensParams {
3327
3489
  *
3328
3490
  * There are two types of tools: **client tools** and **server tools**. The
3329
3491
  * behavior described below applies to client tools. For
3330
- * [server tools](https://docs.claude.com/en/docs/agents-and-tools/tool-use/overview#server-tools),
3492
+ * [server tools](https://platform.claude.com/docs/en/agents-and-tools/tool-use/server-tools),
3331
3493
  * see their individual documentation as each has its own behavior (e.g., the
3332
- * [web search tool](https://docs.claude.com/en/docs/agents-and-tools/tool-use/web-search-tool)).
3494
+ * [web search tool](https://platform.claude.com/docs/en/agents-and-tools/tool-use/web-search-tool)).
3333
3495
  *
3334
3496
  * Each tool definition includes:
3335
3497
  *
@@ -3392,9 +3554,18 @@ export interface MessageCountTokensParams {
3392
3554
  * functions, or more generally whenever you want the model to produce a particular
3393
3555
  * JSON structure of output.
3394
3556
  *
3395
- * See our [guide](https://docs.claude.com/en/docs/tool-use) for more details.
3557
+ * See our
3558
+ * [guide](https://platform.claude.com/docs/en/agents-and-tools/tool-use/overview)
3559
+ * for more details.
3396
3560
  */
3397
3561
  tools?: Array<MessageCountTokensTool>;
3562
+
3563
+ /**
3564
+ * Header param: The user profile ID to attribute this request to. Use when acting
3565
+ * on behalf of a party other than your organization. Requires the `user-profiles`
3566
+ * beta header.
3567
+ */
3568
+ user_profile_id?: string;
3398
3569
  }
3399
3570
 
3400
3571
  Messages.Batches = Batches;
@@ -3548,6 +3719,7 @@ export declare namespace Messages {
3548
3719
  type WebFetchTool20250910 as WebFetchTool20250910,
3549
3720
  type WebFetchTool20260209 as WebFetchTool20260209,
3550
3721
  type WebFetchTool20260309 as WebFetchTool20260309,
3722
+ type WebFetchTool20260318 as WebFetchTool20260318,
3551
3723
  type WebFetchToolResultBlock as WebFetchToolResultBlock,
3552
3724
  type WebFetchToolResultBlockParam as WebFetchToolResultBlockParam,
3553
3725
  type WebFetchToolResultErrorBlock as WebFetchToolResultErrorBlock,
@@ -3557,6 +3729,7 @@ export declare namespace Messages {
3557
3729
  type WebSearchResultBlockParam as WebSearchResultBlockParam,
3558
3730
  type WebSearchTool20250305 as WebSearchTool20250305,
3559
3731
  type WebSearchTool20260209 as WebSearchTool20260209,
3732
+ type WebSearchTool20260318 as WebSearchTool20260318,
3560
3733
  type WebSearchToolRequestError as WebSearchToolRequestError,
3561
3734
  type WebSearchToolResultBlock as WebSearchToolResultBlock,
3562
3735
  type WebSearchToolResultBlockContent as WebSearchToolResultBlockContent,
@@ -34,6 +34,7 @@ async function realpathOrSelf(p: string): Promise<string> {
34
34
  export async function canonicalize(abs: string): Promise<string> {
35
35
  const tail: string[] = [];
36
36
  let prefix = abs;
37
+ let hops = 0;
37
38
  for (;;) {
38
39
  let real: string;
39
40
  try {
@@ -47,7 +48,12 @@ export async function canonicalize(abs: string): Promise<string> {
47
48
  }
48
49
  if (isLink) {
49
50
  // Resolve the symlink ourselves and retry; `tail` (the part below it)
50
- // still applies to the link's target.
51
+ // still applies to the link's target. The hop cap matches Linux
52
+ // MAXSYMLINKS — the same threshold at which `realpath` itself would
53
+ // have returned ELOOP — so a cycle of unresolvable links terminates.
54
+ if (++hops > 40) {
55
+ throw new ToolError(`path ${JSON.stringify(abs)} has too many levels of symbolic links`);
56
+ }
51
57
  prefix = path.resolve(path.dirname(prefix), await fs.readlink(prefix));
52
58
  continue;
53
59
  }
@@ -64,9 +70,10 @@ export async function canonicalize(abs: string): Promise<string> {
64
70
  /**
65
71
  * Resolve `p` and confine it to `root`.
66
72
  *
67
- * Unless `allowOutside` is set, absolute inputs are rejected and the
68
- * **canonical** path is returned every symlink in `p` (including the leaf,
69
- * even a dangling one) is resolved before the confinement check, and the
73
+ * Absolute and relative inputs go through the same canonicalise-then-contain
74
+ * check an absolute path that lands inside `root` is permitted, only paths
75
+ * that resolve *outside* are rejected. Every symlink in `p` (including the
76
+ * leaf, even a dangling one) is resolved before the confinement check, and the
70
77
  * resolved path is what the caller then operates on, so a symlink inside `root`
71
78
  * that points outside it can neither pass the check nor be followed afterwards.
72
79
  *
@@ -81,18 +88,11 @@ export async function confineToRoot(
81
88
  opts?: { allowOutside?: boolean },
82
89
  ): Promise<string> {
83
90
  const allowOutside = opts?.allowOutside ?? false;
84
- if (path.isAbsolute(p)) {
85
- if (!allowOutside) {
86
- throw new ToolError(`absolute path ${JSON.stringify(p)} not permitted`);
87
- }
88
- return path.resolve(p);
89
- }
90
91
  const realRoot = await realpathOrSelf(path.resolve(root));
91
92
  const abs = path.resolve(realRoot, p);
92
93
  if (allowOutside) return abs;
93
94
  const real = await canonicalize(abs);
94
- const rootSep = realRoot.endsWith(path.sep) ? realRoot : realRoot + path.sep;
95
- if (real !== realRoot && !real.startsWith(rootSep)) {
95
+ if (real !== realRoot && !real.startsWith(realRoot + path.sep)) {
96
96
  throw new ToolError(`path ${JSON.stringify(p)} escapes workdir`);
97
97
  }
98
98
  return real;
@@ -95,9 +95,8 @@ export interface AgentToolContext {
95
95
  /** Base directory for resolving relative tool paths. */
96
96
  workdir: string;
97
97
  /**
98
- * When `false` (default), the file tools reject absolute paths and paths
99
- * that escape `workdir` (symlinks resolved). Does **not** constrain
100
- * {@link betaBashTool}.
98
+ * When `false` (default), the file tools reject paths that resolve outside
99
+ * `workdir` (symlinks resolved). Does **not** constrain {@link betaBashTool}.
101
100
  */
102
101
  unrestrictedPaths?: boolean;
103
102
  /**
@@ -161,12 +160,14 @@ export function betaAgentToolset20260401(ctx: AgentToolContext): BetaRunnableToo
161
160
  }
162
161
 
163
162
  /**
164
- * Resolve `p` relative to `ctx.workdir`. Unless `unrestrictedPaths` is set,
165
- * absolute inputs are rejected and the **canonical** path is returned — every
166
- * symlink in `p` (including the leaf, even a dangling one) is resolved before
167
- * the workdir check, and the resolved path is what the tool then operates on, so
168
- * a symlink inside the workdir that points outside it can neither pass the check
169
- * nor be followed afterwards. See the trust model on {@link AgentToolContext}.
163
+ * Resolve `p` against `ctx.workdir`. Absolute and relative inputs go through
164
+ * the same canonicalise-then-contain check an absolute path that lands inside
165
+ * the workdir is permitted, only paths that resolve *outside* are rejected.
166
+ * Every symlink in `p` (including the leaf, even a dangling one) is resolved
167
+ * before the workdir check, and the resolved path is what the tool then operates
168
+ * on, so a symlink inside the workdir that points outside it can neither pass
169
+ * the check nor be followed afterwards. See the trust model on
170
+ * {@link AgentToolContext}.
170
171
  *
171
172
  * Residual TOCTOU: a component could still be swapped for a symlink between this
172
173
  * call and the eventual `fs` operation. Closing that fully needs per-component
@@ -589,6 +590,9 @@ export function betaGlobTool(ctx: AgentToolContext): BetaRunnableTool {
589
590
  if (!ctx.unrestrictedPaths && pat.split(/[\\/]/).includes('..')) {
590
591
  throw new ToolError('glob: ".." is not permitted in the pattern');
591
592
  }
593
+ // Compare canonical against canonical: a workdir that is itself a
594
+ // symlink would otherwise falsely reject every realpath'd match below.
595
+ const realRoot = ctx.unrestrictedPaths ? root : await fs.realpath(root).catch(() => root);
592
596
  const matches: { path: string; mtime: number }[] = [];
593
597
  try {
594
598
  // Native `fs.glob` (Node 22+). `exclude` prunes the noisy dirs the
@@ -600,9 +604,22 @@ export function betaGlobTool(ctx: AgentToolContext): BetaRunnableTool {
600
604
  })) {
601
605
  if (!entry.isFile()) continue;
602
606
  const full = path.join(entry.parentPath, entry.name);
603
- // Defense in depth: drop any match that resolved outside the search
604
- // root (e.g. via a symlinked directory in the tree) when confined.
605
- if (!ctx.unrestrictedPaths && !isWithin(root, full)) continue;
607
+ // Drop any match that resolves outside the search root. A pattern
608
+ // that *names* a symlinked directory (the model controls the
609
+ // pattern, and the bash tool in the same session can plant the
610
+ // link) makes `fs.glob` descend through it and report entries with
611
+ // the raw parent path, so a lexical check on `full` alone would
612
+ // pass `root/link_out/secret` even though it lives outside the
613
+ // jail. Resolve-failure (ELOOP, EACCES, a racing unlink) is a deny.
614
+ if (!ctx.unrestrictedPaths) {
615
+ let real: string;
616
+ try {
617
+ real = await fs.realpath(full);
618
+ } catch {
619
+ continue;
620
+ }
621
+ if (!isWithin(realRoot, real)) continue;
622
+ }
606
623
  let mtime = 0;
607
624
  try {
608
625
  mtime = (await fs.stat(full)).mtimeMs;
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const VERSION = '0.106.0'; // x-release-please-version
1
+ export const VERSION = '0.108.0'; // x-release-please-version
@@ -19,9 +19,10 @@ export declare function canonicalize(abs: string): Promise<string>;
19
19
  /**
20
20
  * Resolve `p` and confine it to `root`.
21
21
  *
22
- * Unless `allowOutside` is set, absolute inputs are rejected and the
23
- * **canonical** path is returned every symlink in `p` (including the leaf,
24
- * even a dangling one) is resolved before the confinement check, and the
22
+ * Absolute and relative inputs go through the same canonicalise-then-contain
23
+ * check an absolute path that lands inside `root` is permitted, only paths
24
+ * that resolve *outside* are rejected. Every symlink in `p` (including the
25
+ * leaf, even a dangling one) is resolved before the confinement check, and the
25
26
  * resolved path is what the caller then operates on, so a symlink inside `root`
26
27
  * that points outside it can neither pass the check nor be followed afterwards.
27
28
  *
@@ -1 +1 @@
1
- {"version":3,"file":"fs-util.d.mts","sourceRoot":"","sources":["../../src/tools/agent-toolset/fs-util.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH,uFAAuF;AACvF,eAAO,MAAM,eAAe,MAAQ,CAAC;AACrC,4CAA4C;AAC5C,eAAO,MAAM,gBAAgB,MAAQ,CAAC;AAWtC;;;;;;GAMG;AACH,wBAAsB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CA4B/D;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,aAAa,CACjC,IAAI,EAAE,MAAM,EACZ,CAAC,EAAE,MAAM,EACT,IAAI,CAAC,EAAE;IAAE,YAAY,CAAC,EAAE,OAAO,CAAA;CAAE,GAChC,OAAO,CAAC,MAAM,CAAC,CAiBjB;AAED;;;;GAIG;AACH,wBAAsB,eAAe,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAgBxF;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAwBjE"}
1
+ {"version":3,"file":"fs-util.d.mts","sourceRoot":"","sources":["../../src/tools/agent-toolset/fs-util.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH,uFAAuF;AACvF,eAAO,MAAM,eAAe,MAAQ,CAAC;AACrC,4CAA4C;AAC5C,eAAO,MAAM,gBAAgB,MAAQ,CAAC;AAWtC;;;;;;GAMG;AACH,wBAAsB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAkC/D;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,aAAa,CACjC,IAAI,EAAE,MAAM,EACZ,CAAC,EAAE,MAAM,EACT,IAAI,CAAC,EAAE;IAAE,YAAY,CAAC,EAAE,OAAO,CAAA;CAAE,GAChC,OAAO,CAAC,MAAM,CAAC,CAUjB;AAED;;;;GAIG;AACH,wBAAsB,eAAe,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAgBxF;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAwBjE"}
@@ -19,9 +19,10 @@ export declare function canonicalize(abs: string): Promise<string>;
19
19
  /**
20
20
  * Resolve `p` and confine it to `root`.
21
21
  *
22
- * Unless `allowOutside` is set, absolute inputs are rejected and the
23
- * **canonical** path is returned every symlink in `p` (including the leaf,
24
- * even a dangling one) is resolved before the confinement check, and the
22
+ * Absolute and relative inputs go through the same canonicalise-then-contain
23
+ * check an absolute path that lands inside `root` is permitted, only paths
24
+ * that resolve *outside* are rejected. Every symlink in `p` (including the
25
+ * leaf, even a dangling one) is resolved before the confinement check, and the
25
26
  * resolved path is what the caller then operates on, so a symlink inside `root`
26
27
  * that points outside it can neither pass the check nor be followed afterwards.
27
28
  *
@@ -1 +1 @@
1
- {"version":3,"file":"fs-util.d.ts","sourceRoot":"","sources":["../../src/tools/agent-toolset/fs-util.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH,uFAAuF;AACvF,eAAO,MAAM,eAAe,MAAQ,CAAC;AACrC,4CAA4C;AAC5C,eAAO,MAAM,gBAAgB,MAAQ,CAAC;AAWtC;;;;;;GAMG;AACH,wBAAsB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CA4B/D;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,aAAa,CACjC,IAAI,EAAE,MAAM,EACZ,CAAC,EAAE,MAAM,EACT,IAAI,CAAC,EAAE;IAAE,YAAY,CAAC,EAAE,OAAO,CAAA;CAAE,GAChC,OAAO,CAAC,MAAM,CAAC,CAiBjB;AAED;;;;GAIG;AACH,wBAAsB,eAAe,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAgBxF;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAwBjE"}
1
+ {"version":3,"file":"fs-util.d.ts","sourceRoot":"","sources":["../../src/tools/agent-toolset/fs-util.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH,uFAAuF;AACvF,eAAO,MAAM,eAAe,MAAQ,CAAC;AACrC,4CAA4C;AAC5C,eAAO,MAAM,gBAAgB,MAAQ,CAAC;AAWtC;;;;;;GAMG;AACH,wBAAsB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAkC/D;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,aAAa,CACjC,IAAI,EAAE,MAAM,EACZ,CAAC,EAAE,MAAM,EACT,IAAI,CAAC,EAAE;IAAE,YAAY,CAAC,EAAE,OAAO,CAAA;CAAE,GAChC,OAAO,CAAC,MAAM,CAAC,CAUjB;AAED;;;;GAIG;AACH,wBAAsB,eAAe,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAgBxF;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAwBjE"}