anthropic 2.7.0 → 2.9.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +62 -0
- data/README.md +1 -1
- data/lib/anthropic/error_classes.rb +4 -0
- data/lib/anthropic/helpers/bedrock/client.rb +17 -5
- data/lib/anthropic/helpers/google_cloud/client.rb +4 -1
- data/lib/anthropic/helpers/threads/beta_message_thread.rb +30 -6
- data/lib/anthropic/helpers/tools/runner.rb +21 -4
- data/lib/anthropic/helpers/tracing/streamed_message.rb +8 -1
- data/lib/anthropic/helpers/vertex/client.rb +26 -12
- data/lib/anthropic/internal/tracing.rb +1 -0
- data/lib/anthropic/internal/type/file_input.rb +11 -0
- data/lib/anthropic/internal/util.rb +43 -11
- data/lib/anthropic/models/anthropic_beta.rb +44 -30
- data/lib/anthropic/models/beta/beta_managed_agents_agent_toolset_default_config.rb +1 -1
- data/lib/anthropic/models/beta/beta_managed_agents_agent_toolset_default_config_params.rb +1 -1
- data/lib/anthropic/models/beta/beta_managed_agents_auto_policy.rb +3 -1
- data/lib/anthropic/models/beta/beta_managed_agents_bash_tool_config.rb +1 -1
- data/lib/anthropic/models/beta/beta_managed_agents_bash_tool_config_params.rb +1 -1
- data/lib/anthropic/models/beta/beta_managed_agents_edit_tool_config.rb +1 -1
- data/lib/anthropic/models/beta/beta_managed_agents_edit_tool_config_params.rb +1 -1
- data/lib/anthropic/models/beta/beta_managed_agents_glob_tool_config.rb +1 -1
- data/lib/anthropic/models/beta/beta_managed_agents_glob_tool_config_params.rb +1 -1
- data/lib/anthropic/models/beta/beta_managed_agents_grep_tool_config.rb +1 -1
- data/lib/anthropic/models/beta/beta_managed_agents_grep_tool_config_params.rb +1 -1
- data/lib/anthropic/models/beta/beta_managed_agents_mcp_tool_config.rb +1 -1
- data/lib/anthropic/models/beta/beta_managed_agents_mcp_tool_config_params.rb +1 -1
- data/lib/anthropic/models/beta/beta_managed_agents_mcp_toolset_default_config.rb +1 -1
- data/lib/anthropic/models/beta/beta_managed_agents_mcp_toolset_default_config_params.rb +1 -1
- data/lib/anthropic/models/beta/beta_managed_agents_model.rb +1 -1
- data/lib/anthropic/models/beta/beta_managed_agents_multiagent_coordinator_params.rb +3 -2
- data/lib/anthropic/models/beta/beta_managed_agents_multiagent_params.rb +1 -1
- data/lib/anthropic/models/beta/beta_managed_agents_read_tool_config.rb +1 -1
- data/lib/anthropic/models/beta/beta_managed_agents_read_tool_config_params.rb +1 -1
- data/lib/anthropic/models/beta/beta_managed_agents_web_fetch_tool_config.rb +1 -1
- data/lib/anthropic/models/beta/beta_managed_agents_web_fetch_tool_config_params.rb +1 -1
- data/lib/anthropic/models/beta/beta_managed_agents_web_search_tool_config.rb +1 -1
- data/lib/anthropic/models/beta/beta_managed_agents_web_search_tool_config_params.rb +1 -1
- data/lib/anthropic/models/beta/beta_managed_agents_write_tool_config.rb +1 -1
- data/lib/anthropic/models/beta/beta_managed_agents_write_tool_config_params.rb +1 -1
- data/lib/anthropic/models/beta/organization/beta_analytics_claude_tag_metrics.rb +42 -0
- data/lib/anthropic/models/beta/organization/beta_analytics_single_day_activity_summary.rb +43 -1
- data/lib/anthropic/models/beta/organization/beta_analytics_user_activity.rb +14 -1
- data/lib/anthropic/models/beta/organization/beta_bundle_attachment_not_supported_error.rb +24 -0
- data/lib/anthropic/models/beta/organization/beta_bundle_attachment_not_supported_error_details.rb +22 -0
- data/lib/anthropic/models/beta/organization/beta_bundle_on_call_error.rb +24 -0
- data/lib/anthropic/models/beta/organization/beta_bundle_on_call_error_details.rb +22 -0
- data/lib/anthropic/models/beta/organization/beta_claude_tag_reply_mode.rb +68 -0
- data/lib/anthropic/models/beta/organization/beta_claude_tag_reply_mode_always_awake.rb +22 -0
- data/lib/anthropic/models/beta/organization/beta_claude_tag_reply_mode_automatic.rb +22 -0
- data/lib/anthropic/models/beta/organization/beta_claude_tag_reply_mode_mention_only.rb +21 -0
- data/lib/anthropic/models/beta/organization/beta_claude_tag_reply_mode_thread.rb +23 -0
- data/lib/anthropic/models/beta/organization/beta_claude_tag_setting_sources.rb +14 -1
- data/lib/anthropic/models/beta/organization/beta_claude_tag_settings.rb +20 -3
- data/lib/anthropic/models/beta/organization/beta_claude_tag_settings_create.rb +22 -2
- data/lib/anthropic/models/beta/organization/beta_claude_tag_settings_update.rb +22 -2
- data/lib/anthropic/models/beta/organization/beta_external_key.rb +2 -2
- data/lib/anthropic/models/beta/organization/beta_rbac_role.rb +13 -4
- data/lib/anthropic/models/beta/organization/beta_rbac_role_source.rb +52 -0
- data/lib/anthropic/models/beta/organization/beta_rbac_role_source_built_in.rb +25 -0
- data/lib/anthropic/models/beta/organization/beta_rbac_role_source_custom.rb +20 -0
- data/lib/anthropic/models/beta/organization/claude_tag/beta_claude_tag_bundle.rb +15 -2
- data/lib/anthropic/models/beta/organization/claude_tag/bundle_update_params.rb +50 -0
- data/lib/anthropic/models/beta/organization/external_key_create_params.rb +8 -5
- data/lib/anthropic/models/beta/organization/plugin_list_params.rb +2 -1
- data/lib/anthropic/models/beta/organization/plugin_marketplace_list_params.rb +2 -1
- data/lib/anthropic/models/beta/organization/plugin_marketplace_retrieve_params.rb +2 -1
- data/lib/anthropic/models/beta/organization/plugin_retrieve_params.rb +2 -1
- data/lib/anthropic/models/beta/organization/plugins/installation_setting_list_params.rb +2 -1
- data/lib/anthropic/models/beta/organization/plugins/share_list_params.rb +2 -1
- data/lib/anthropic/models/beta/organization/plugins/version_download_params.rb +2 -1
- data/lib/anthropic/models/beta/organization/plugins/version_list_params.rb +2 -1
- data/lib/anthropic/models/beta/organization/plugins/version_retrieve_params.rb +2 -1
- data/lib/anthropic/models/beta/organization/workspace_update_params.rb +2 -1
- data/lib/anthropic/models/beta/sessions/beta_managed_agents_agent_auto_evaluated_permission.rb +1 -1
- data/lib/anthropic/models/beta/sessions/beta_managed_agents_agent_auto_evaluated_permission_deny.rb +7 -4
- data/lib/anthropic/models/error_details.rb +28 -3
- data/lib/anthropic/models/model.rb +2 -2
- data/lib/anthropic/models/organization/analytics_claude_tag_metrics.rb +39 -0
- data/lib/anthropic/models/organization/analytics_single_day_activity_summary.rb +43 -1
- data/lib/anthropic/models/organization/analytics_user_activity.rb +12 -1
- data/lib/anthropic/models/organization/external_key.rb +2 -2
- data/lib/anthropic/models/organization/external_key_create_params.rb +8 -5
- data/lib/anthropic/models/organization/key_profile_mismatch_error.rb +3 -3
- data/lib/anthropic/models/organization/key_profile_mismatch_error_details.rb +3 -3
- data/lib/anthropic/models/organization/rbac_role.rb +13 -4
- data/lib/anthropic/models/organization/rbac_role_source.rb +50 -0
- data/lib/anthropic/models/organization/rbac_role_source_built_in.rb +22 -0
- data/lib/anthropic/models/organization/rbac_role_source_custom.rb +18 -0
- data/lib/anthropic/models/organization/workspace_update_params.rb +2 -1
- data/lib/anthropic/models/parent_organization_required_error.rb +20 -0
- data/lib/anthropic/models/parent_organization_required_error_details.rb +18 -0
- data/lib/anthropic/models/rbac_role_not_found_error.rb +19 -0
- data/lib/anthropic/models/rbac_role_not_found_error_details.rb +17 -0
- data/lib/anthropic/models.rb +8 -0
- data/lib/anthropic/resources/beta/messages/batches.rb +6 -6
- data/lib/anthropic/resources/beta/messages.rb +5 -1
- data/lib/anthropic/resources/beta/organization/claude_tag/bundles.rb +51 -0
- data/lib/anthropic/resources/beta/organization/external_keys.rb +1 -1
- data/lib/anthropic/resources/beta/organization/plugins/versions.rb +4 -5
- data/lib/anthropic/resources/beta/organization/plugins.rb +13 -12
- data/lib/anthropic/resources/beta/organization/rbac_roles/permissions.rb +4 -0
- data/lib/anthropic/resources/beta/organization/rbac_roles.rb +7 -0
- data/lib/anthropic/resources/organization/external_keys.rb +1 -1
- data/lib/anthropic/resources/organization/rbac_roles/permissions.rb +4 -0
- data/lib/anthropic/resources/organization/rbac_roles.rb +7 -0
- data/lib/anthropic/version.rb +1 -1
- data/lib/anthropic.rb +22 -0
- data/rbi/anthropic/helpers/bedrock/client.rbi +6 -2
- data/rbi/anthropic/helpers/bedrock/event_stream.rbi +12 -3
- data/rbi/anthropic/helpers/bedrock/mantle_client.rbi +3 -1
- data/rbi/anthropic/helpers/google_cloud/client.rbi +3 -1
- data/rbi/anthropic/helpers/refusal_fallback.rbi +12 -4
- data/rbi/anthropic/helpers/vertex/client.rbi +6 -2
- data/rbi/anthropic/internal/tracing.rbi +2 -0
- data/rbi/anthropic/internal/util.rbi +2 -2
- data/rbi/anthropic/models/anthropic_beta.rbi +41 -41
- data/rbi/anthropic/models/beta/beta_managed_agents_auto_policy.rbi +3 -1
- data/rbi/anthropic/models/beta/beta_managed_agents_model.rbi +1 -1
- data/rbi/anthropic/models/beta/beta_managed_agents_multiagent_coordinator_params.rbi +3 -2
- data/rbi/anthropic/models/beta/organization/beta_analytics_claude_tag_metrics.rbi +69 -0
- data/rbi/anthropic/models/beta/organization/beta_analytics_single_day_activity_summary.rbi +60 -0
- data/rbi/anthropic/models/beta/organization/beta_analytics_user_activity.rbi +36 -0
- data/rbi/anthropic/models/beta/organization/beta_bundle_attachment_not_supported_error.rbi +25 -0
- data/rbi/anthropic/models/beta/organization/beta_bundle_attachment_not_supported_error_details.rbi +32 -0
- data/rbi/anthropic/models/beta/organization/beta_bundle_on_call_error.rbi +23 -0
- data/rbi/anthropic/models/beta/organization/beta_bundle_on_call_error_details.rbi +32 -0
- data/rbi/anthropic/models/beta/organization/beta_claude_tag_reply_mode.rbi +92 -0
- data/rbi/anthropic/models/beta/organization/beta_claude_tag_reply_mode_always_awake.rbi +32 -0
- data/rbi/anthropic/models/beta/organization/beta_claude_tag_reply_mode_automatic.rbi +32 -0
- data/rbi/anthropic/models/beta/organization/beta_claude_tag_reply_mode_mention_only.rbi +31 -0
- data/rbi/anthropic/models/beta/organization/beta_claude_tag_reply_mode_thread.rbi +33 -0
- data/rbi/anthropic/models/beta/organization/beta_claude_tag_setting_sources.rbi +30 -1
- data/rbi/anthropic/models/beta/organization/beta_claude_tag_settings.rbi +39 -5
- data/rbi/anthropic/models/beta/organization/beta_claude_tag_settings_create.rbi +56 -5
- data/rbi/anthropic/models/beta/organization/beta_claude_tag_settings_update.rbi +56 -5
- data/rbi/anthropic/models/beta/organization/beta_external_key.rbi +4 -4
- data/rbi/anthropic/models/beta/organization/beta_rbac_role.rbi +21 -4
- data/rbi/anthropic/models/beta/organization/beta_rbac_role_source.rbi +78 -0
- data/rbi/anthropic/models/beta/organization/beta_rbac_role_source_built_in.rbi +36 -0
- data/rbi/anthropic/models/beta/organization/beta_rbac_role_source_custom.rbi +34 -0
- data/rbi/anthropic/models/beta/organization/claude_tag/beta_claude_tag_bundle.rbi +11 -1
- data/rbi/anthropic/models/beta/organization/claude_tag/bundle_update_params.rbi +88 -0
- data/rbi/anthropic/models/beta/organization/external_key_create_params.rbi +14 -8
- data/rbi/anthropic/models/beta/organization/plugin_list_params.rbi +4 -2
- data/rbi/anthropic/models/beta/organization/plugin_marketplace_list_params.rbi +4 -2
- data/rbi/anthropic/models/beta/organization/plugin_marketplace_retrieve_params.rbi +4 -2
- data/rbi/anthropic/models/beta/organization/plugin_retrieve_params.rbi +4 -2
- data/rbi/anthropic/models/beta/organization/plugins/installation_setting_list_params.rbi +4 -2
- data/rbi/anthropic/models/beta/organization/plugins/share_list_params.rbi +4 -2
- data/rbi/anthropic/models/beta/organization/plugins/version_download_params.rbi +4 -2
- data/rbi/anthropic/models/beta/organization/plugins/version_list_params.rbi +4 -2
- data/rbi/anthropic/models/beta/organization/plugins/version_retrieve_params.rbi +4 -2
- data/rbi/anthropic/models/beta/organization/workspace_update_params.rbi +4 -2
- data/rbi/anthropic/models/beta/sessions/beta_managed_agents_agent_auto_evaluated_permission_deny.rbi +10 -6
- data/rbi/anthropic/models/error_details.rbi +25 -1
- data/rbi/anthropic/models/model.rbi +2 -2
- data/rbi/anthropic/models/organization/analytics_claude_tag_metrics.rbi +67 -0
- data/rbi/anthropic/models/organization/analytics_single_day_activity_summary.rbi +60 -0
- data/rbi/anthropic/models/organization/analytics_user_activity.rbi +30 -0
- data/rbi/anthropic/models/organization/external_key.rbi +4 -4
- data/rbi/anthropic/models/organization/external_key_create_params.rbi +14 -8
- data/rbi/anthropic/models/organization/key_profile_mismatch_error.rbi +3 -3
- data/rbi/anthropic/models/organization/key_profile_mismatch_error_details.rbi +3 -3
- data/rbi/anthropic/models/organization/rbac_role.rbi +18 -4
- data/rbi/anthropic/models/organization/rbac_role_source.rbi +68 -0
- data/rbi/anthropic/models/organization/rbac_role_source_built_in.rbi +34 -0
- data/rbi/anthropic/models/organization/rbac_role_source_custom.rbi +32 -0
- data/rbi/anthropic/models/organization/workspace_update_params.rbi +4 -2
- data/rbi/anthropic/models/parent_organization_required_error.rbi +17 -0
- data/rbi/anthropic/models/parent_organization_required_error_details.rbi +28 -0
- data/rbi/anthropic/models/rbac_role_not_found_error.rbi +16 -0
- data/rbi/anthropic/models/rbac_role_not_found_error_details.rbi +27 -0
- data/rbi/anthropic/models.rbi +10 -0
- data/rbi/anthropic/resources/beta/organization/claude_tag/bundles.rbi +30 -0
- data/rbi/anthropic/resources/beta/organization/external_keys.rbi +7 -4
- data/rbi/anthropic/resources/beta/organization/plugin_marketplaces.rbi +4 -2
- data/rbi/anthropic/resources/beta/organization/plugins/installation_settings.rbi +2 -1
- data/rbi/anthropic/resources/beta/organization/plugins/shares.rbi +2 -1
- data/rbi/anthropic/resources/beta/organization/plugins/versions.rbi +10 -8
- data/rbi/anthropic/resources/beta/organization/plugins.rbi +17 -14
- data/rbi/anthropic/resources/beta/organization/workspaces.rbi +2 -1
- data/rbi/anthropic/resources/organization/external_keys.rbi +7 -4
- data/rbi/anthropic/resources/organization/workspaces.rbi +2 -1
- data/rbi/lib/anthropic/helpers/stainless_helper_header.rbi +6 -1
- data/sig/anthropic/helpers/sessions/event_accumulator.rbs +6 -2
- data/sig/anthropic/internal/tracing.rbs +1 -0
- data/sig/anthropic/internal/util.rbs +1 -1
- data/sig/anthropic/models/anthropic_beta.rbs +21 -21
- data/sig/anthropic/models/beta/beta_managed_agents_model.rbs +1 -1
- data/sig/anthropic/models/beta/organization/beta_analytics_claude_tag_metrics.rbs +26 -0
- data/sig/anthropic/models/beta/organization/beta_analytics_single_day_activity_summary.rbs +15 -0
- data/sig/anthropic/models/beta/organization/beta_analytics_user_activity.rbs +5 -0
- data/sig/anthropic/models/beta/organization/beta_bundle_attachment_not_supported_error.rbs +13 -0
- data/sig/anthropic/models/beta/organization/beta_bundle_attachment_not_supported_error_details.rbs +20 -0
- data/sig/anthropic/models/beta/organization/beta_bundle_on_call_error.rbs +13 -0
- data/sig/anthropic/models/beta/organization/beta_bundle_on_call_error_details.rbs +17 -0
- data/sig/anthropic/models/beta/organization/beta_claude_tag_reply_mode.rbs +50 -0
- data/sig/anthropic/models/beta/organization/beta_claude_tag_reply_mode_always_awake.rbs +17 -0
- data/sig/anthropic/models/beta/organization/beta_claude_tag_reply_mode_automatic.rbs +17 -0
- data/sig/anthropic/models/beta/organization/beta_claude_tag_reply_mode_mention_only.rbs +17 -0
- data/sig/anthropic/models/beta/organization/beta_claude_tag_reply_mode_thread.rbs +17 -0
- data/sig/anthropic/models/beta/organization/beta_claude_tag_setting_sources.rbs +8 -3
- data/sig/anthropic/models/beta/organization/beta_claude_tag_settings.rbs +8 -3
- data/sig/anthropic/models/beta/organization/beta_claude_tag_settings_create.rbs +8 -3
- data/sig/anthropic/models/beta/organization/beta_claude_tag_settings_update.rbs +8 -3
- data/sig/anthropic/models/beta/organization/beta_rbac_role.rbs +5 -0
- data/sig/anthropic/models/beta/organization/beta_rbac_role_source.rbs +40 -0
- data/sig/anthropic/models/beta/organization/beta_rbac_role_source_built_in.rbs +17 -0
- data/sig/anthropic/models/beta/organization/beta_rbac_role_source_custom.rbs +17 -0
- data/sig/anthropic/models/beta/organization/claude_tag/beta_claude_tag_bundle.rbs +5 -0
- data/sig/anthropic/models/beta/organization/claude_tag/bundle_update_params.rbs +46 -0
- data/sig/anthropic/models/error_details.rbs +26 -0
- data/sig/anthropic/models/model.rbs +2 -2
- data/sig/anthropic/models/organization/analytics_claude_tag_metrics.rbs +24 -0
- data/sig/anthropic/models/organization/analytics_single_day_activity_summary.rbs +15 -0
- data/sig/anthropic/models/organization/analytics_user_activity.rbs +5 -0
- data/sig/anthropic/models/organization/rbac_role.rbs +5 -0
- data/sig/anthropic/models/organization/rbac_role_source.rbs +38 -0
- data/sig/anthropic/models/organization/rbac_role_source_built_in.rbs +15 -0
- data/sig/anthropic/models/organization/rbac_role_source_custom.rbs +15 -0
- data/sig/anthropic/models/parent_organization_required_error.rbs +9 -0
- data/sig/anthropic/models/parent_organization_required_error_details.rbs +14 -0
- data/sig/anthropic/models/rbac_role_not_found_error.rbs +9 -0
- data/sig/anthropic/models/rbac_role_not_found_error_details.rbs +14 -0
- data/sig/anthropic/models.rbs +8 -0
- data/sig/anthropic/resources/beta/organization/claude_tag/bundles.rbs +7 -0
- metadata +68 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b3bbd83e128f33453e53c83fe2b1ea780ff8bea17e4e9ece8db76d237455be74
|
|
4
|
+
data.tar.gz: 2f057fc46beea13bf5aef689375b1ea2ac5df8715f2801a08b2af5be5755ff6d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a75d011512d8ad9469e5f4353b1d117527f688379aa9b8290eea955398ce6aec8c9d721d2e14912c4a96ab92886552d592d36a712e919c9c5a5866ccccb48a1c
|
|
7
|
+
data.tar.gz: 52fe69d1d15a30d70b28aa097f01009c9aa8bd717568324c4c5a42133e17cf6c0eefc8bbf27ed1ce56119bf164258115f36879f7537a5cbd17f46adad9618875
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,67 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [2.9.0](https://github.com/anthropics/anthropic-sdk-ruby/compare/v2.8.0...v2.9.0) (2026-11-16)
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
* **api:** add source and error codes to the RBAC Role read endpoints
|
|
8
|
+
* **api:** add Update Bundle, which sets a Claude Tag Bundle's instructions, and return instructions on Bundle
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* **client:** keep a streamed request body from breaking the next request
|
|
14
|
+
* **client:** read a response as JSON Lines only for JSON Lines types
|
|
15
|
+
* **client:** send an Enumerator request body in full on every attempt
|
|
16
|
+
* **client:** send multipart uploads with non-ASCII text, and stop corrupting AWS uploads on older Rubies
|
|
17
|
+
* **client:** upload a Tempfile's contents, not "#<File:0x...>"
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Chores
|
|
21
|
+
|
|
22
|
+
* **api:** deprecate old beta header values
|
|
23
|
+
|
|
24
|
+
The API still accepts these values, but a later release removes them from the SDKs. Delete `prompt-caching-2024-07-31`, `pdfs-2024-09-25`, `token-counting-2024-11-01`, `token-efficient-tools-2025-02-19`, `extended-cache-ttl-2025-04-11`, `cache-diagnosis-2026-04-07` and `ce-user-management-2026-07-13` from your requests. `files-api-2025-04-14` and `skills-2025-10-02` select the beta response shapes, so follow the Files API and Skills migration guides before you delete them.
|
|
25
|
+
|
|
26
|
+
In C#, the `AnthropicBeta` enum's members have new numbers, so code compiled against an earlier SDK version sends a different beta value, with no error, until you rebuild it.
|
|
27
|
+
|
|
28
|
+
* **api:** stop sending an old beta header on batch requests
|
|
29
|
+
|
|
30
|
+
`beta.messages.batches` no longer sends `message-batches-2024-09-24`, which the API doesn't need. If your client sets a default `anthropic-beta` header, these requests now send it, where in some SDKs the old value replaced it. The API still accepts the old value. If you set it yourself, delete it: a later release removes it from the SDKs.
|
|
31
|
+
|
|
32
|
+
* **docs:** add an example value for the workspace name
|
|
33
|
+
* **docs:** clarify when the auto permission policy denies a tool call
|
|
34
|
+
* **docs:** clarify which workspaces an external key can be attached to
|
|
35
|
+
* **docs:** recommend multiagent_20261001 over the coordinator type
|
|
36
|
+
* **docs:** say when organization_id is required on plugin reads
|
|
37
|
+
* **internal:** format hand-written code with scripts/format
|
|
38
|
+
|
|
39
|
+
## [2.8.0](https://github.com/anthropics/anthropic-sdk-ruby/compare/v2.7.0...v2.8.0) (2026-11-10)
|
|
40
|
+
|
|
41
|
+
### Features
|
|
42
|
+
|
|
43
|
+
* **api:** add Claude Tag metrics to the analytics summaries and users reports
|
|
44
|
+
* **api:** add reply_mode to Claude Tag Slack channel settings
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
### Bug Fixes
|
|
48
|
+
|
|
49
|
+
* **bedrock:** raise `ArgumentError` before sending when the model is empty, `"."` or `".."` before its `;` parameters, such as `";x"` or `"..;x"`, which some servers and proxies read as the empty or dot segment
|
|
50
|
+
* **bedrock:** raise `ArgumentError` before sending when the model is empty, `"."` or `".."`, which would send the request to a different URL, and send the model ID's `:` as it is in the request path rather than as `%3A`
|
|
51
|
+
* **google-cloud:** percent-encode the project, location and workspace ID in the derived base URL, so a `/` in one no longer adds path segments, and raise `ArgumentError` when one is empty, `"."` or `".."`
|
|
52
|
+
* **vertex:** percent-encode the project ID, region and model in the request path, so a `/` in one no longer adds path segments, and raise `ArgumentError` before sending when the project ID or region is `"."` or `".."`
|
|
53
|
+
* **vertex:** raise `ArgumentError` before sending when the model is empty, missing or only `;` parameters, such as `";x"`, rather than sending the request to `.../models/:rawPredict`, and when it is `"."` or `".."` followed by `;` parameters, such as `"..;x"`, which some servers and proxies read as the dot segment
|
|
54
|
+
* **vertex:** send a `;` in the model as `%3B` in the request path, so a server or proxy that drops `;` and the rest of a path segment no longer drops `:rawPredict` or `:streamRawPredict` with it
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
### Chores
|
|
58
|
+
|
|
59
|
+
* **docs:** clarify display_name for RBAC Roles created by Anthropic
|
|
60
|
+
* **docs:** clarify plugin delete and skill name conflict descriptions
|
|
61
|
+
* **docs:** clarify when to omit user_profile_id on external keys
|
|
62
|
+
* **docs:** note that Claude Tag settings accept self-hosted runner pools
|
|
63
|
+
* **docs:** update model descriptions
|
|
64
|
+
|
|
3
65
|
## [2.7.0](https://github.com/anthropics/anthropic-sdk-ruby/compare/v2.6.0...v2.7.0) (2026-11-09)
|
|
4
66
|
|
|
5
67
|
### Features
|
data/README.md
CHANGED
|
@@ -25,6 +25,8 @@ module Anthropic
|
|
|
25
25
|
[529, nil] => Anthropic::Errors::OverloadedError,
|
|
26
26
|
[400, "already_member"] => Anthropic::Models::Organization::AlreadyMemberError,
|
|
27
27
|
[400, "available_tools_limit_exceeded"] => Anthropic::Models::AvailableToolsLimitExceededError,
|
|
28
|
+
[400, "bundle_attachment_not_supported"] => Anthropic::Models::Beta::Organization::BetaBundleAttachmentNotSupportedError,
|
|
29
|
+
[400, "bundle_on_call"] => Anthropic::Models::Beta::Organization::BetaBundleOnCallError,
|
|
28
30
|
[400, "cannot_invite_emails_with_unverified_domains"] => Anthropic::Models::Organization::CannotInviteEmailsWithUnverifiedDomainsError,
|
|
29
31
|
[400, "cannot_remove_last_member"] => Anthropic::Models::Organization::CannotRemoveLastMemberError,
|
|
30
32
|
[400, "cannot_sign_out_primary_owner"] => Anthropic::Models::Beta::Organization::BetaCannotSignOutPrimaryOwnerError,
|
|
@@ -56,6 +58,7 @@ module Anthropic
|
|
|
56
58
|
[400, "organization_not_enrolled_in_beta"] => Anthropic::Models::BetaOrganizationNotEnrolledInBetaError,
|
|
57
59
|
[400, "organization_on_hold"] => Anthropic::Models::OrganizationOnHoldError,
|
|
58
60
|
[400, "organization_type_not_supported"] => Anthropic::Models::OrganizationTypeNotSupportedError,
|
|
61
|
+
[400, "parent_organization_required"] => Anthropic::Models::ParentOrganizationRequiredError,
|
|
59
62
|
[400, "rbac_group_grants_owner_access"] => Anthropic::Models::Organization::RBACGroupGrantsOwnerAccessError,
|
|
60
63
|
[400, "rbac_group_owner_access_unconfirmed"] => Anthropic::Models::Organization::RBACGroupOwnerAccessUnconfirmedError,
|
|
61
64
|
[400, "request_body_encoding_invalid"] => Anthropic::Models::RequestBodyEncodingInvalidError,
|
|
@@ -88,6 +91,7 @@ module Anthropic
|
|
|
88
91
|
[403, "spend_limits_admin_api_writes_not_enabled"] => Anthropic::Models::Beta::Organization::BetaSpendLimitsAdminAPIWritesNotEnabledError,
|
|
89
92
|
[404, "environment_not_found"] => Anthropic::Models::Beta::BetaEnvironmentNotFoundError,
|
|
90
93
|
[404, "file_expired"] => Anthropic::Models::FileExpiredError,
|
|
94
|
+
[404, "rbac_role_not_found"] => Anthropic::Models::RBACRoleNotFoundError,
|
|
91
95
|
[404, "slack_channel_set_up_environment_not_found"] => Anthropic::Models::Beta::Organization::BetaSlackChannelSetUpEnvironmentNotFoundError,
|
|
92
96
|
[404, "thread_not_found"] => Anthropic::Models::ThreadNotFoundError,
|
|
93
97
|
[409, "concurrent_membership_change"] => Anthropic::Models::ConcurrentMembershipChangeError,
|
|
@@ -357,14 +357,26 @@ module Anthropic
|
|
|
357
357
|
|
|
358
358
|
return req.with(body: body) unless req.method == :post && messages_route
|
|
359
359
|
|
|
360
|
-
model =
|
|
360
|
+
model = Anthropic::Internal::Util.encode_path(body.delete(:model).to_s)
|
|
361
361
|
stream = body.delete(:stream) || false
|
|
362
|
+
invoke_path = stream ? "model/#{model}/invoke-with-response-stream" : "model/#{model}/invoke"
|
|
363
|
+
# Servers and proxies collapse an empty segment and resolve a dot segment,
|
|
364
|
+
# some of them after dropping the segment's `;` parameters.
|
|
365
|
+
problem =
|
|
366
|
+
if model.empty? || model.start_with?(";")
|
|
367
|
+
"an empty path parameter"
|
|
368
|
+
elsif model == "." || model == ".." || model.start_with?(".;", "..;")
|
|
369
|
+
"the dot segment #{model.inspect}"
|
|
370
|
+
end
|
|
371
|
+
if problem
|
|
372
|
+
raise ArgumentError.new(
|
|
373
|
+
"The request was not sent: path #{invoke_path.inspect} has #{problem}, " \
|
|
374
|
+
"which would send it to a different URL"
|
|
375
|
+
)
|
|
376
|
+
end
|
|
362
377
|
|
|
363
378
|
url = req.url.dup
|
|
364
|
-
url.path = path.sub(
|
|
365
|
-
%r{v1/messages\z},
|
|
366
|
-
stream ? "model/#{model}/invoke-with-response-stream" : "model/#{model}/invoke"
|
|
367
|
-
)
|
|
379
|
+
url.path = path.sub(%r{v1/messages\z}, invoke_path)
|
|
368
380
|
url.query = nil
|
|
369
381
|
|
|
370
382
|
req.with(body: body, url: url)
|
|
@@ -301,7 +301,10 @@ module Anthropic
|
|
|
301
301
|
"application default credentials with a project."
|
|
302
302
|
)
|
|
303
303
|
end
|
|
304
|
-
|
|
304
|
+
segments = {project: @project, location: @location, workspace_id: @workspace_id}.transform_values do
|
|
305
|
+
_1 && Anthropic::Internal::Util.interpolate_path(["%1$s", _1])
|
|
306
|
+
end
|
|
307
|
+
format(template, **segments)
|
|
305
308
|
end
|
|
306
309
|
|
|
307
310
|
# @api private
|
|
@@ -11,7 +11,9 @@ module Anthropic
|
|
|
11
11
|
THREADS_BETA = Anthropic::Models::AnthropicBeta::MESSAGE_THREADS_2026_08_12.to_s
|
|
12
12
|
NOT_FOUND_ERROR_CODE = "thread_not_found"
|
|
13
13
|
# A `continue` rejected with one of these is sent again as a `create`.
|
|
14
|
-
REPLAY_ERROR_CODES = Set[NOT_FOUND_ERROR_CODE,
|
|
14
|
+
REPLAY_ERROR_CODES = Set[NOT_FOUND_ERROR_CODE,
|
|
15
|
+
"thread_already_continued",
|
|
16
|
+
"thread_continue_in_flight"].freeze
|
|
15
17
|
UNSUPPORTED_REQUEST_ERROR_CODE = "thread_unsupported_request"
|
|
16
18
|
UNSUPPORTED_REQUEST_BEHAVIORS = Set[:error, :continue_unthreaded].freeze
|
|
17
19
|
|
|
@@ -455,7 +457,16 @@ module Anthropic
|
|
|
455
457
|
value.except(:cache_control, "cache_control").to_h do |key, nested|
|
|
456
458
|
next [key, nested] unless %w[content source tool definition tool_references].include?(key.to_s)
|
|
457
459
|
|
|
458
|
-
[
|
|
460
|
+
[
|
|
461
|
+
key,
|
|
462
|
+
if nested.is_a?(Array)
|
|
463
|
+
nested.map do
|
|
464
|
+
without_cache_control(_1)
|
|
465
|
+
end
|
|
466
|
+
else
|
|
467
|
+
without_cache_control(nested)
|
|
468
|
+
end
|
|
469
|
+
]
|
|
459
470
|
end
|
|
460
471
|
end
|
|
461
472
|
|
|
@@ -463,11 +474,20 @@ module Anthropic
|
|
|
463
474
|
# as the API would receive it, and the classes that its tool inputs and output parse into
|
|
464
475
|
def wire_request(fields)
|
|
465
476
|
wire, = Anthropic::Models::Beta::MessageCreateParams.dump_request(fields)
|
|
466
|
-
tools, models = Anthropic::Helpers::Messages.distill_input_schema_models!(
|
|
477
|
+
tools, models = Anthropic::Helpers::Messages.distill_input_schema_models!(
|
|
478
|
+
wire,
|
|
479
|
+
strict: nil,
|
|
480
|
+
is_beta: true
|
|
481
|
+
)
|
|
467
482
|
[wire, tools, models]
|
|
468
483
|
end
|
|
469
484
|
|
|
470
|
-
def create_only_fields(wire)
|
|
485
|
+
def create_only_fields(wire)
|
|
486
|
+
{
|
|
487
|
+
system_: wire[:system],
|
|
488
|
+
tools: wire[:tools]
|
|
489
|
+
}.transform_values(&:to_json)
|
|
490
|
+
end
|
|
471
491
|
|
|
472
492
|
def refuse_change!(created_with)
|
|
473
493
|
return if !@anchor.is_a?(Continue) || created_with == @anchor.created_with
|
|
@@ -495,14 +515,18 @@ module Anthropic
|
|
|
495
515
|
in Anthropic::Models::Beta::BetaToolUseBlock[type: :tool_use] if (tool = request.tools[block.name])
|
|
496
516
|
Anthropic::Internal::Type::Converter.coerce(tool, block.input)
|
|
497
517
|
in Anthropic::Models::Beta::BetaTextBlock if (model = request.models.first&.last)
|
|
498
|
-
Anthropic::Internal::Type::Converter.coerce(
|
|
518
|
+
Anthropic::Internal::Type::Converter.coerce(
|
|
519
|
+
model,
|
|
520
|
+
JSON.parse(block.text, symbolize_names: true)
|
|
521
|
+
)
|
|
499
522
|
else
|
|
500
523
|
next
|
|
501
524
|
end
|
|
502
525
|
rescue StandardError => e
|
|
503
526
|
{error: e.message}
|
|
504
527
|
end
|
|
505
|
-
reply.content[index] =
|
|
528
|
+
reply.content[index] =
|
|
529
|
+
Anthropic::Internal::Type::Converter.coerce(block.class, {**block.to_h, parsed:})
|
|
506
530
|
end
|
|
507
531
|
end
|
|
508
532
|
|
|
@@ -272,7 +272,11 @@ module Anthropic
|
|
|
272
272
|
raise
|
|
273
273
|
ensure
|
|
274
274
|
if tool_runner_span
|
|
275
|
-
Anthropic::Helpers::Tracing.end_tool_runner_span(
|
|
275
|
+
Anthropic::Helpers::Tracing.end_tool_runner_span(
|
|
276
|
+
tool_runner_span,
|
|
277
|
+
returned: returned,
|
|
278
|
+
error: error
|
|
279
|
+
)
|
|
276
280
|
end
|
|
277
281
|
@tool_runner_otel_context, @app_otel_context, @stopped_by_app = outer
|
|
278
282
|
end
|
|
@@ -349,7 +353,12 @@ module Anthropic
|
|
|
349
353
|
begin
|
|
350
354
|
# `parsed` was read against `params[:tools]`, which an added tool is not in.
|
|
351
355
|
input = tool_use.parsed
|
|
352
|
-
|
|
356
|
+
if @tool_overrides.key?(tool_use.name)
|
|
357
|
+
input = Anthropic::Internal::Type::Converter.coerce(
|
|
358
|
+
tool,
|
|
359
|
+
tool_use.input
|
|
360
|
+
)
|
|
361
|
+
end
|
|
353
362
|
run = proc { tool.call(input) }
|
|
354
363
|
raw = tool_use_span ? OpenTelemetry::Trace.with_span(tool_use_span, &run) : run.call
|
|
355
364
|
is_error = false
|
|
@@ -360,7 +369,12 @@ module Anthropic
|
|
|
360
369
|
if tool_use_span
|
|
361
370
|
# `is_error` is unset when the run was interrupted, and then so is the span's status.
|
|
362
371
|
result = {content: tool_result_content(raw), is_error:} unless is_error.nil?
|
|
363
|
-
Anthropic::Helpers::Tracing.end_tool_use_span(
|
|
372
|
+
Anthropic::Helpers::Tracing.end_tool_use_span(
|
|
373
|
+
@client,
|
|
374
|
+
tool_use_span,
|
|
375
|
+
tool_use.input,
|
|
376
|
+
result
|
|
377
|
+
)
|
|
364
378
|
end
|
|
365
379
|
end
|
|
366
380
|
else
|
|
@@ -597,7 +611,10 @@ module Anthropic
|
|
|
597
611
|
# A compaction response replaces the history, `tool_removal` blocks included, so what the
|
|
598
612
|
# history took away is taken out of the overrides first.
|
|
599
613
|
private def keep_removals_from_history
|
|
600
|
-
runnable = [
|
|
614
|
+
runnable = [
|
|
615
|
+
*params[:tools].to_a.grep(Anthropic::Helpers::Tools::BaseTool),
|
|
616
|
+
*@tool_overrides.values.compact
|
|
617
|
+
]
|
|
601
618
|
names = runnable.map { Anthropic::Helpers::Messages.tool_api_name(_1) }
|
|
602
619
|
(names - available_tool_names(runnable).to_a).each { @tool_overrides.store(_1, nil) }
|
|
603
620
|
end
|
|
@@ -26,7 +26,14 @@ module Anthropic
|
|
|
26
26
|
# @param content_limit [Integer] the most bytes the `content` attributes hold
|
|
27
27
|
#
|
|
28
28
|
# @return [Array(Enumerator, Anthropic::Helpers::Tracing::StreamedMessage)]
|
|
29
|
-
def follow_streamed_message(
|
|
29
|
+
def follow_streamed_message(
|
|
30
|
+
span,
|
|
31
|
+
events,
|
|
32
|
+
params:,
|
|
33
|
+
start_time:,
|
|
34
|
+
content:,
|
|
35
|
+
content_limit: CONTENT_LIMIT
|
|
36
|
+
)
|
|
30
37
|
tracker = StreamedMessage.new(
|
|
31
38
|
span,
|
|
32
39
|
params: params,
|
|
@@ -279,26 +279,40 @@ module Anthropic
|
|
|
279
279
|
end
|
|
280
280
|
end
|
|
281
281
|
|
|
282
|
+
models_path = -> do
|
|
283
|
+
Anthropic::Internal::Util.interpolate_path(
|
|
284
|
+
["projects/%1$s/locations/%2$s/publishers/anthropic/models", @project_id, region]
|
|
285
|
+
)
|
|
286
|
+
end
|
|
287
|
+
|
|
282
288
|
if req.method == :post && query_ok && path.end_with?("/v1/messages")
|
|
283
289
|
unless body.is_a?(Hash)
|
|
284
290
|
raise ArgumentError.new("Expected json data to be a hash for post /v1/messages")
|
|
285
291
|
end
|
|
286
292
|
|
|
287
|
-
model = body.delete(:model)
|
|
293
|
+
model = Anthropic::Internal::Util.encode_path(body.delete(:model).to_s)
|
|
288
294
|
specifier = body[:stream] ? "streamRawPredict" : "rawPredict"
|
|
295
|
+
predict_path = ->(name) { "#{models_path.call}/#{name}:#{specifier}" }
|
|
296
|
+
# With its `:specifier` a model of `..` is not a dot segment. Some servers and proxies
|
|
297
|
+
# drop a segment's `;` parameters, though, and here the specifier goes with them.
|
|
298
|
+
problem =
|
|
299
|
+
if model.empty? || model.start_with?(";")
|
|
300
|
+
"an empty path parameter"
|
|
301
|
+
elsif model.start_with?(".;", "..;")
|
|
302
|
+
"the dot segment #{model.inspect}"
|
|
303
|
+
end
|
|
304
|
+
if problem
|
|
305
|
+
raise ArgumentError.new(
|
|
306
|
+
"The request was not sent: path #{predict_path.call(model).inspect} has #{problem}, " \
|
|
307
|
+
"which would send it to a different URL"
|
|
308
|
+
)
|
|
309
|
+
end
|
|
289
310
|
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
%r{v1/messages\z},
|
|
293
|
-
"projects/#{@project_id}/locations/#{region}/publishers/anthropic/models/#{model}:#{specifier}"
|
|
294
|
-
)
|
|
311
|
+
# A server that drops `;` and the rest of a segment would drop the specifier too.
|
|
312
|
+
url = rewrite_path(url, %r{v1/messages\z}, predict_path.call(model.gsub(";", "%3B")))
|
|
295
313
|
elsif req.method == :post && query_ok && path.end_with?("/v1/messages/count_tokens")
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
%r{v1/messages/count_tokens\z},
|
|
299
|
-
"projects/#{@project_id}/locations/#{region}/publishers/anthropic/" \
|
|
300
|
-
"models/count-tokens:rawPredict"
|
|
301
|
-
)
|
|
314
|
+
count_tokens_path = "#{models_path.call}/count-tokens:rawPredict"
|
|
315
|
+
url = rewrite_path(url, %r{v1/messages/count_tokens\z}, count_tokens_path)
|
|
302
316
|
end
|
|
303
317
|
|
|
304
318
|
return req if body.equal?(req.body) && headers.equal?(req.headers) && url.equal?(req.url)
|
|
@@ -366,6 +366,7 @@ module Anthropic
|
|
|
366
366
|
"anthropic.organization.claude_tag.slack_workspaces.update"
|
|
367
367
|
ORGANIZATION_CLAUDE_TAG_SLACK_WORKSPACES_LIST = "anthropic.organization.claude_tag.slack_workspaces.list"
|
|
368
368
|
ORGANIZATION_CLAUDE_TAG_BUNDLES_RETRIEVE = "anthropic.organization.claude_tag.bundles.retrieve"
|
|
369
|
+
ORGANIZATION_CLAUDE_TAG_BUNDLES_UPDATE = "anthropic.organization.claude_tag.bundles.update"
|
|
369
370
|
ORGANIZATION_CLAUDE_TAG_BUNDLES_LIST = "anthropic.organization.claude_tag.bundles.list"
|
|
370
371
|
ORGANIZATION_CLAUDE_TAG_BUNDLES_TARGETS_CREATE =
|
|
371
372
|
"anthropic.organization.claude_tag.bundles.targets.create"
|
|
@@ -92,6 +92,17 @@ module Anthropic
|
|
|
92
92
|
in Anthropic::FilePart if value.content.is_a?(IO)
|
|
93
93
|
state[:can_retry] = false
|
|
94
94
|
value
|
|
95
|
+
in Anthropic::FilePart if IO.try_convert(value.content)
|
|
96
|
+
dump(
|
|
97
|
+
Anthropic::FilePart.new(
|
|
98
|
+
value.content.to_io,
|
|
99
|
+
filename: value.filename,
|
|
100
|
+
content_type: value.content_type
|
|
101
|
+
),
|
|
102
|
+
state: state
|
|
103
|
+
)
|
|
104
|
+
in -> { IO.try_convert(_1) }
|
|
105
|
+
dump(value.to_io, state: state)
|
|
95
106
|
else
|
|
96
107
|
value
|
|
97
108
|
end
|
|
@@ -473,18 +473,23 @@ module Anthropic
|
|
|
473
473
|
#
|
|
474
474
|
# @param max_len [Integer, nil]
|
|
475
475
|
#
|
|
476
|
-
# @return [String]
|
|
476
|
+
# @return [String, nil]
|
|
477
477
|
private def read_enum(max_len)
|
|
478
478
|
case max_len
|
|
479
479
|
in nil
|
|
480
|
-
@stream.
|
|
480
|
+
loop { @buf << @stream.next }
|
|
481
|
+
@stream = nil
|
|
482
|
+
@buf.slice!(0..)
|
|
481
483
|
in Integer
|
|
482
484
|
@buf << @stream.next while @buf.length < max_len
|
|
483
|
-
@buf.slice!(
|
|
485
|
+
@buf.slice!(0, max_len)
|
|
484
486
|
end
|
|
485
487
|
rescue StopIteration
|
|
486
488
|
@stream = nil
|
|
487
|
-
|
|
489
|
+
# Return nil, not "", once the body is used up, as `IO#read(length)` does: Net::HTTP sends each read as a
|
|
490
|
+
# chunk, and an empty chunk ends the body, so "" would end it twice and break the next request on the
|
|
491
|
+
# connection.
|
|
492
|
+
@buf.slice!(0..) unless @buf.empty?
|
|
488
493
|
end
|
|
489
494
|
|
|
490
495
|
# @api private
|
|
@@ -496,15 +501,19 @@ module Anthropic
|
|
|
496
501
|
def read(max_len = nil, out_string = nil)
|
|
497
502
|
case @stream
|
|
498
503
|
in nil
|
|
504
|
+
out_string&.clear
|
|
499
505
|
nil
|
|
500
506
|
in IO | StringIO
|
|
501
507
|
@stream.read(max_len, out_string)
|
|
502
508
|
in Enumerator
|
|
503
509
|
read = read_enum(max_len)
|
|
504
|
-
case out_string
|
|
505
|
-
in String
|
|
510
|
+
case [out_string, read]
|
|
511
|
+
in [String, String]
|
|
506
512
|
out_string.replace(read)
|
|
507
|
-
in nil
|
|
513
|
+
in [String, nil]
|
|
514
|
+
out_string.clear
|
|
515
|
+
nil
|
|
516
|
+
in [nil, _]
|
|
508
517
|
read
|
|
509
518
|
end
|
|
510
519
|
end
|
|
@@ -525,6 +534,10 @@ module Anthropic
|
|
|
525
534
|
in Pathname
|
|
526
535
|
@closing = true
|
|
527
536
|
src.open(binmode: true)
|
|
537
|
+
in Enumerator
|
|
538
|
+
# Each retry or redirect reads the same body through a new adapter. Calling `next` on `src` itself would
|
|
539
|
+
# resume where the previous adapter stopped; `to_enum` starts from the beginning.
|
|
540
|
+
src.to_enum
|
|
528
541
|
else
|
|
529
542
|
src
|
|
530
543
|
end
|
|
@@ -540,8 +553,10 @@ module Anthropic
|
|
|
540
553
|
# @return [Enumerable<String>]
|
|
541
554
|
def writable_enum(&blk)
|
|
542
555
|
Enumerator.new do |y|
|
|
556
|
+
y.define_singleton_method(:<<) { super(_1.b) }
|
|
543
557
|
y.define_singleton_method(:write) do
|
|
544
|
-
|
|
558
|
+
# `IO.copy_stream` reuses its buffer. With Ruby bug #21131, a `dup` or `b` of it changes on the next read.
|
|
559
|
+
self << (String.new(capacity: _1.bytesize) << _1)
|
|
545
560
|
_1.bytesize
|
|
546
561
|
end
|
|
547
562
|
|
|
@@ -553,7 +568,7 @@ module Anthropic
|
|
|
553
568
|
# @type [Regexp]
|
|
554
569
|
JSON_CONTENT = %r{^application/(?:[a-zA-Z0-9.-]+\+)?json(?!l)}
|
|
555
570
|
# @type [Regexp]
|
|
556
|
-
JSONL_CONTENT = %r{^application/(
|
|
571
|
+
JSONL_CONTENT = %r{^application/(?:x-(?:n|l)djson|(?:x-)?jsonl)}
|
|
557
572
|
|
|
558
573
|
class << self
|
|
559
574
|
# @api private
|
|
@@ -685,6 +700,9 @@ module Anthropic
|
|
|
685
700
|
# RFC 1521 Section 7.2.1 says we should have 70 char maximum for boundary length
|
|
686
701
|
boundary = SecureRandom.urlsafe_base64(30)
|
|
687
702
|
|
|
703
|
+
# Each read of `strio` runs this block from the start, so a retry or redirect sends the whole body. A read
|
|
704
|
+
# stopped partway skips the `ensure` below; `ReadIOAdapter#close` then starts a new read and stops it at the
|
|
705
|
+
# first chunk, and that read's `ensure` closes every file left in `closing`.
|
|
688
706
|
closing = []
|
|
689
707
|
strio = writable_enum do |y|
|
|
690
708
|
case body
|
|
@@ -703,10 +721,24 @@ module Anthropic
|
|
|
703
721
|
write_multipart_chunk(y, boundary: boundary, key: nil, val: body, closing: closing)
|
|
704
722
|
end
|
|
705
723
|
y << "--#{boundary}--\r\n"
|
|
724
|
+
ensure
|
|
725
|
+
closing.each(&:call)
|
|
726
|
+
closing.clear
|
|
727
|
+
end
|
|
728
|
+
|
|
729
|
+
# An IO can be read only once, so a second read of `strio` would send the other parts with an empty file part.
|
|
730
|
+
# `fused_enum` yields nothing instead. Resource methods turn retries off for a body holding an IO; a retry
|
|
731
|
+
# through `client.request`, or a 307 or 308 redirect, can still send it without the file's contents.
|
|
732
|
+
parts = if body.is_a?(Hash)
|
|
733
|
+
body.values.flat_map { _1.is_a?(Array) ? _1 : [_1] }
|
|
734
|
+
else
|
|
735
|
+
[body]
|
|
736
|
+
end
|
|
737
|
+
if parts.any? { _1.is_a?(IO) || (_1.is_a?(Anthropic::FilePart) && _1.content.is_a?(IO)) }
|
|
738
|
+
return [boundary, fused_enum(strio) { closing.each(&:call) }]
|
|
706
739
|
end
|
|
707
740
|
|
|
708
|
-
|
|
709
|
-
[boundary, fused_io]
|
|
741
|
+
[boundary, strio]
|
|
710
742
|
# rubocop:enable Style/CaseEquality
|
|
711
743
|
end
|
|
712
744
|
|