claude-agent-sdk 0.37.0 → 1.0.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 (35) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +17 -0
  3. data/README.md +6 -2
  4. data/UPGRADING-1.0.md +151 -0
  5. data/docs/errors.md +6 -0
  6. data/docs/sessions.md +20 -1
  7. data/docs/types.md +17 -14
  8. data/lib/claude_agent_sdk/deprecation.rb +1 -40
  9. data/lib/claude_agent_sdk/errors.rb +10 -0
  10. data/lib/claude_agent_sdk/session_resume.rb +11 -5
  11. data/lib/claude_agent_sdk/types/attributes.rb +14 -49
  12. data/lib/claude_agent_sdk/types/base.rb +2 -0
  13. data/lib/claude_agent_sdk/version.rb +1 -1
  14. data/lib/claude_agent_sdk.rb +11 -11
  15. data/sig/claude_agent_sdk/cancellation_signal.rbs +14 -0
  16. data/sig/claude_agent_sdk/configuration.rbs +14 -0
  17. data/sig/claude_agent_sdk/errors.rbs +86 -0
  18. data/sig/claude_agent_sdk/observer.rbs +42 -0
  19. data/sig/claude_agent_sdk/railtie.rbs +10 -0
  20. data/sig/claude_agent_sdk/sdk_mcp_server.rbs +76 -0
  21. data/sig/claude_agent_sdk/session_store.rbs +105 -0
  22. data/sig/claude_agent_sdk/streaming.rbs +15 -0
  23. data/sig/claude_agent_sdk/transport.rbs +98 -0
  24. data/sig/claude_agent_sdk/types/base.rbs +39 -0
  25. data/sig/claude_agent_sdk/types/content_blocks.rbs +79 -0
  26. data/sig/claude_agent_sdk/types/hooks.rbs +528 -0
  27. data/sig/claude_agent_sdk/types/mcp.rbs +216 -0
  28. data/sig/claude_agent_sdk/types/messages.rbs +586 -0
  29. data/sig/claude_agent_sdk/types/option_values.rbs +245 -0
  30. data/sig/claude_agent_sdk/types/options.rbs +288 -0
  31. data/sig/claude_agent_sdk/types/permissions.rbs +108 -0
  32. data/sig/claude_agent_sdk/types/sessions.rbs +66 -0
  33. data/sig/claude_agent_sdk.rbs +231 -0
  34. data/sig/manifest.yaml +5 -0
  35. metadata +22 -1
@@ -0,0 +1,66 @@
1
+ module ClaudeAgentSDK
2
+ # Returned by ClaudeAgentSDK.fork_session.
3
+ class ForkSessionResult < Type
4
+ # The new (forked) session's id.
5
+ attr_accessor session_id: String?
6
+ end
7
+
8
+ # Session metadata returned by list_sessions / get_session_info. A plain
9
+ # class (not a Type): snake_case accessors only.
10
+ class SDKSessionInfo
11
+ attr_accessor session_id: String
12
+
13
+ attr_accessor summary: String
14
+
15
+ # Epoch milliseconds.
16
+ attr_accessor last_modified: Integer
17
+
18
+ # Bytes (nil for store-backed sessions).
19
+ attr_accessor file_size: Integer?
20
+
21
+ attr_accessor custom_title: String?
22
+
23
+ attr_accessor first_prompt: String?
24
+
25
+ attr_accessor git_branch: String?
26
+
27
+ attr_accessor cwd: String?
28
+
29
+ attr_accessor tag: String?
30
+
31
+ # Epoch milliseconds.
32
+ attr_accessor created_at: Integer?
33
+
34
+ def initialize: (session_id: String, summary: String, last_modified: Integer, ?file_size: Integer?, ?custom_title: String?, ?first_prompt: String?, ?git_branch: String?, ?cwd: String?, ?tag: String?, ?created_at: Integer?) -> void
35
+ end
36
+
37
+ # One message of a session transcript (get_session_messages /
38
+ # get_subagent_messages). A plain class (not a Type).
39
+ class SessionMessage
40
+ # "user" or "assistant".
41
+ attr_accessor type: String
42
+
43
+ attr_accessor uuid: String
44
+
45
+ attr_accessor session_id: String
46
+
47
+ # The raw API message, String keys as in the JSONL (docs/types.md#hash-keys).
48
+ attr_accessor message: transcript_hash?
49
+
50
+ # Subagent messages only: the Agent tool_use id that spawned it.
51
+ attr_accessor parent_tool_use_id: String?
52
+
53
+ # Nested subagent messages only: the spawning subagent's id.
54
+ attr_accessor parent_agent_id: String?
55
+
56
+ def initialize: (type: String, uuid: String, session_id: String, message: transcript_hash?, ?parent_tool_use_id: String?, ?parent_agent_id: String?) -> void
57
+
58
+ # Concatenated text ("" when there is none).
59
+ def text: () -> String
60
+
61
+ alias to_s text
62
+
63
+ # Typed content blocks ([] without array-of-blocks content).
64
+ def content_blocks: () -> Array[content_block]
65
+ end
66
+ end
@@ -0,0 +1,231 @@
1
+ # RBS signatures for the claude-agent-sdk public API.
2
+ #
3
+ # Scope: the 1.0 SemVer surface only, i.e. everything documented in docs/ and
4
+ # every YARD object NOT tagged `@api private` (see CONTRIBUTING.md, "What is
5
+ # public API"). Internals (Query, MessageParser, Sessions, FiberBoundary, ...)
6
+ # deliberately have no signatures here, so typing them never freezes them.
7
+ # Where a public signature has to mention an internal or third-party object,
8
+ # it uses a narrow interface or `untyped` with a comment.
9
+ #
10
+ # Hash-key rule (docs/types.md#hash-keys): Hashes passed through from the
11
+ # CLI's stream-JSON have Symbol keys spelled as on the wire (`wire_hash`);
12
+ # transcripts read from disk or a SessionStore have String keys
13
+ # (`transcript_hash`).
14
+ #
15
+ # One file per area: sig/claude_agent_sdk/*.rbs, with the value types under
16
+ # sig/claude_agent_sdk/types/ mirroring lib/claude_agent_sdk/types/.
17
+ module ClaudeAgentSDK
18
+ VERSION: String
19
+
20
+ # A Hash from the CLI's stream-JSON, passed through untouched: Symbol keys,
21
+ # spelled exactly as on the wire (camelCase stays camelCase).
22
+ type wire_hash = Hash[Symbol, untyped]
23
+
24
+ # A transcript entry / summary / subagent metadata Hash read from disk or a
25
+ # SessionStore: String keys, spelled as in the JSONL.
26
+ type transcript_hash = Hash[String, untyped]
27
+
28
+ # Every message `query` / `Client#receive_messages` yields (typed
29
+ # SystemMessage subclasses are included via SystemMessage).
30
+ type message = UserMessage
31
+ | AssistantMessage
32
+ | SystemMessage
33
+ | ResultMessage
34
+ | StreamEvent
35
+ | RateLimitEvent
36
+ | ConversationResetMessage
37
+ | ToolProgressMessage
38
+ | AuthStatusMessage
39
+ | ToolUseSummaryMessage
40
+ | PromptSuggestionMessage
41
+
42
+ # A prompt: a String, or anything iterable (an Enumerator, an Array, ...)
43
+ # of message Hashes / JSONL Strings (see Streaming). A bare Hash is
44
+ # rejected with ArgumentError.
45
+ type prompt = String | _Each[Hash[untyped, untyped] | String]
46
+
47
+ # Middleware around every user-callback dispatch
48
+ # (ClaudeAgentOptions#callback_wrapper): receives a zero-arg invocation, must
49
+ # call it and return its value.
50
+ interface _CallbackWrapper
51
+ def call: (_Invocation invocation) -> untyped
52
+ end
53
+
54
+ # The zero-arg invocation a callback wrapper receives.
55
+ interface _Invocation
56
+ def call: () -> untyped
57
+ end
58
+
59
+ # ---- One-shot queries ----
60
+
61
+ # Streams every message of a one-shot query to the block; without a block,
62
+ # returns an Enumerator (internal iteration only: #each / #first / #to_a,
63
+ # never #next).
64
+ def self.query: (prompt: prompt, ?options: ClaudeAgentOptions?, ?transport: _Transport?) { (message) -> void } -> void
65
+ | (prompt: prompt, ?options: ClaudeAgentOptions?, ?transport: _Transport?) -> Enumerator[message, void]
66
+
67
+ # Runs a query to completion and returns its final ResultMessage. The
68
+ # optional block observes every message (it cannot end the stream early).
69
+ def self.ask: (prompt prompt, ?options: ClaudeAgentOptions?, ?transport: _Transport?) ?{ (message) -> void } -> ResultMessage
70
+
71
+ # Runs a heavy block on a plain thread (a no-op hop outside a Fiber
72
+ # scheduler) and returns its value; exceptions propagate.
73
+ def self.offload: [T] () { () -> T } -> T
74
+
75
+ # ---- Global configuration (lib/claude_agent_sdk/configuration.rb) ----
76
+
77
+ def self.configure: [T] () { (Configuration config) -> T } -> T
78
+
79
+ def self.configuration: () -> Configuration
80
+
81
+ def self.reset_configuration: () -> Configuration
82
+
83
+ # The frozen snapshot set via `configuration.default_options=`.
84
+ def self.default_options: () -> Hash[Symbol | String, untyped]
85
+
86
+ # ---- SDK MCP servers (lib/claude_agent_sdk/sdk_mcp_server.rb) ----
87
+
88
+ def self.create_tool: (String | Symbol name, String description, Hash[untyped, untyped] input_schema, ?annotations: Hash[Symbol | String, untyped]?, ?meta: Hash[String | Symbol, untyped]?) { (wire_hash args) -> tool_result } -> SdkMcpTool
89
+
90
+ def self.create_resource: (uri: String, name: String, ?description: String?, ?mime_type: String?) { () -> Hash[Symbol | String, untyped] } -> SdkMcpResource
91
+
92
+ def self.create_prompt: (name: String, ?description: String?, ?arguments: Array[Hash[Symbol | String, untyped]]?) { (wire_hash args) -> Hash[Symbol | String, untyped] } -> SdkMcpPrompt
93
+
94
+ # Returns the `{ type: 'sdk', name:, instance: }` config Hash to put under
95
+ # ClaudeAgentOptions#mcp_servers.
96
+ def self.create_sdk_mcp_server: (name: String, ?version: String, ?tools: Array[SdkMcpTool], ?resources: Array[SdkMcpResource], ?prompts: Array[SdkMcpPrompt]) -> { type: String, name: String, instance: SdkMcpServer }
97
+
98
+ # ---- Sessions (local disk by default; pass session_store: to use a store) ----
99
+
100
+ # include_worktrees filters only on disk (nil reads as false there); with a
101
+ # session_store anything but the default true raises ArgumentError.
102
+ def self.list_sessions: (?directory: String?, ?limit: Integer?, ?offset: Integer, ?include_worktrees: bool?, ?session_store: _SessionStore?) -> Array[SDKSessionInfo]
103
+
104
+ def self.get_session_info: (session_id: String, ?directory: String?, ?session_store: _SessionStore?) -> SDKSessionInfo?
105
+
106
+ def self.get_session_messages: (session_id: String, ?directory: String?, ?limit: Integer?, ?offset: Integer, ?session_store: _SessionStore?) -> Array[SessionMessage]
107
+
108
+ def self.list_subagents: (session_id: String, ?directory: String?, ?session_store: _SessionStore?) -> Array[String]
109
+
110
+ def self.get_subagent_metadata: (session_id: String, agent_id: String, ?directory: String?, ?session_store: _SessionStore?) -> transcript_hash?
111
+
112
+ def self.get_subagent_messages: (session_id: String, agent_id: String, ?directory: String?, ?limit: Integer?, ?offset: Integer, ?session_store: _SessionStore?) -> Array[SessionMessage]
113
+
114
+ def self.rename_session: (session_id: String, title: String, ?directory: String?, ?session_store: _SessionStore?) -> void
115
+
116
+ def self.tag_session: (session_id: String, tag: String?, ?directory: String?, ?session_store: _SessionStore?) -> void
117
+
118
+ def self.delete_session: (session_id: String, ?directory: String?, ?session_store: _SessionStore?) -> void
119
+
120
+ def self.fork_session: (session_id: String, ?directory: String?, ?up_to_message_id: String?, ?title: String?, ?session_store: _SessionStore?) -> ForkSessionResult
121
+
122
+ # The SessionStore project_key for a directory (default: the cwd).
123
+ def self.project_key_for_directory: (?(String | Pathname)? directory) -> String
124
+
125
+ # Folds appended transcript entries into a running session summary; for
126
+ # SessionStore adapters to call from #append (see
127
+ # SessionStore#list_session_summaries).
128
+ def self.fold_session_summary: (transcript_hash? prev, session_key key, Array[transcript_hash] entries) -> session_summary
129
+
130
+ # Replays a local transcript into a store; batch_size (default 500, also
131
+ # for nil) is the number of entries per SessionStore#append.
132
+ def self.import_session_to_store: (session_id: String, session_store: _SessionStore, ?directory: String?, ?include_subagents: bool, ?batch_size: Integer?) -> void
133
+
134
+ # @deprecated Use .list_sessions with session_store:. Public (with a
135
+ # one-time warning) through 1.x; removed in 2.0.
136
+ def self.list_sessions_from_store: (session_store: _SessionStore, ?directory: String?, ?limit: Integer?, ?offset: Integer) -> Array[SDKSessionInfo]
137
+
138
+ # @deprecated Use .get_session_info with session_store:.
139
+ def self.get_session_info_from_store: (session_store: _SessionStore, session_id: String, ?directory: String?) -> SDKSessionInfo?
140
+
141
+ # @deprecated Use .get_session_messages with session_store:.
142
+ def self.get_session_messages_from_store: (session_store: _SessionStore, session_id: String, ?directory: String?, ?limit: Integer?, ?offset: Integer) -> Array[SessionMessage]
143
+
144
+ # @deprecated Use .list_subagents with session_store:.
145
+ def self.list_subagents_from_store: (session_store: _SessionStore, session_id: String, ?directory: String?) -> Array[String]
146
+
147
+ # @deprecated Use .get_subagent_metadata with session_store:.
148
+ def self.get_subagent_metadata_from_store: (session_store: _SessionStore, session_id: String, agent_id: String, ?directory: String?) -> transcript_hash?
149
+
150
+ # @deprecated Use .get_subagent_messages with session_store:.
151
+ def self.get_subagent_messages_from_store: (session_store: _SessionStore, session_id: String, agent_id: String, ?directory: String?, ?limit: Integer?, ?offset: Integer) -> Array[SessionMessage]
152
+
153
+ # @deprecated Use .rename_session with session_store:.
154
+ def self.rename_session_via_store: (session_store: _SessionStore, session_id: String, title: String, ?directory: String?) -> void
155
+
156
+ # @deprecated Use .tag_session with session_store:.
157
+ def self.tag_session_via_store: (session_store: _SessionStore, session_id: String, tag: String?, ?directory: String?) -> void
158
+
159
+ # @deprecated Use .delete_session with session_store:.
160
+ def self.delete_session_via_store: (session_store: _SessionStore, session_id: String, ?directory: String?) -> void
161
+
162
+ # @deprecated Use .fork_session with session_store:.
163
+ def self.fork_session_via_store: (session_store: _SessionStore, session_id: String, ?directory: String?, ?up_to_message_id: String?, ?title: String?) -> ForkSessionResult
164
+
165
+ # Bidirectional, interactive sessions. Every method but #server_info and
166
+ # #disconnect raises CLIConnectionError before #connect.
167
+ class Client
168
+ def initialize: (?options: ClaudeAgentOptions?, ?transport_class: _TransportClass, ?transport_args: Hash[Symbol, untyped]) -> void
169
+
170
+ # Connects, yields the client, and always disconnects; returns the
171
+ # block's value.
172
+ def self.open: [T] (?prompt? prompt, ?options: ClaudeAgentOptions?, ?transport_class: _TransportClass, ?transport_args: Hash[Symbol, untyped]) { (Client client) -> T } -> T
173
+
174
+ # A String is sent as the first user message; an iterable prompt is
175
+ # streamed in the background as the session's input.
176
+ def connect: (?prompt? prompt) -> void
177
+
178
+ def query: (prompt prompt, ?session_id: String) -> void
179
+
180
+ def receive_messages: () { (message) -> void } -> void
181
+ | () -> Enumerator[message, void]
182
+
183
+ # Like #receive_messages, but stops after the next ResultMessage.
184
+ def receive_response: () { (message) -> void } -> void
185
+ | () -> Enumerator[message, void]
186
+
187
+ def interrupt: () -> void
188
+
189
+ def set_permission_mode: (String mode) -> void
190
+
191
+ # Ruby-style spelling of #set_permission_mode.
192
+ def permission_mode=: (String mode) -> void
193
+
194
+ def set_model: (String? model) -> void
195
+
196
+ # Ruby-style spelling of #set_model.
197
+ def model=: (String? model) -> void
198
+
199
+ def reconnect_mcp_server: (String server_name) -> void
200
+
201
+ def toggle_mcp_server: (String server_name, bool enabled) -> void
202
+
203
+ def stop_task: (String task_id) -> void
204
+
205
+ # `{ backgrounded: true | false }` with a tool_use_id, `{}` without.
206
+ def background_tasks: (?tool_use_id: String?) -> Hash[Symbol, bool]
207
+
208
+ def rewind_files: (String user_message_uuid) -> void
209
+
210
+ # The CLI's initialize response (wire_hash), or nil before #connect.
211
+ def server_info: () -> wire_hash?
212
+
213
+ def get_server_info: () -> wire_hash?
214
+
215
+ # Context-window usage breakdown, passed through from the CLI (wire_hash).
216
+ def get_context_usage: () -> wire_hash
217
+
218
+ # Ruby-style spelling of #get_context_usage.
219
+ def context_usage: () -> wire_hash
220
+
221
+ # MCP server connection status, passed through from the CLI (wire_hash:
222
+ # `mcp_status[:mcpServers]`); McpStatusResponse.parse gives a typed view.
223
+ def get_mcp_status: () -> wire_hash
224
+
225
+ # Ruby-style spelling of #get_mcp_status.
226
+ def mcp_status: () -> wire_hash
227
+
228
+ # Idempotent; safe after a failed #connect.
229
+ def disconnect: () -> void
230
+ end
231
+ end
data/sig/manifest.yaml ADDED
@@ -0,0 +1,5 @@
1
+ # Standard libraries these signatures reference, loaded by `rbs collection`
2
+ # for projects that use this gem's sig/. Pathname is core from RBS 4; RBS 3
3
+ # needs the stdlib signatures.
4
+ dependencies:
5
+ - name: pathname
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: claude-agent-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.37.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ya-luotao
@@ -121,6 +121,7 @@ files:
121
121
  - CHANGELOG.md
122
122
  - LICENSE
123
123
  - README.md
124
+ - UPGRADING-1.0.md
124
125
  - docs/cli-installer.md
125
126
  - docs/client.md
126
127
  - docs/configuration.md
@@ -175,6 +176,26 @@ files:
175
176
  - lib/claude_agent_sdk/version.rb
176
177
  - lib/generators/claude_agent_sdk/install/install_generator.rb
177
178
  - lib/generators/claude_agent_sdk/install/templates/claude_agent_sdk.rb.tt
179
+ - sig/claude_agent_sdk.rbs
180
+ - sig/claude_agent_sdk/cancellation_signal.rbs
181
+ - sig/claude_agent_sdk/configuration.rbs
182
+ - sig/claude_agent_sdk/errors.rbs
183
+ - sig/claude_agent_sdk/observer.rbs
184
+ - sig/claude_agent_sdk/railtie.rbs
185
+ - sig/claude_agent_sdk/sdk_mcp_server.rbs
186
+ - sig/claude_agent_sdk/session_store.rbs
187
+ - sig/claude_agent_sdk/streaming.rbs
188
+ - sig/claude_agent_sdk/transport.rbs
189
+ - sig/claude_agent_sdk/types/base.rbs
190
+ - sig/claude_agent_sdk/types/content_blocks.rbs
191
+ - sig/claude_agent_sdk/types/hooks.rbs
192
+ - sig/claude_agent_sdk/types/mcp.rbs
193
+ - sig/claude_agent_sdk/types/messages.rbs
194
+ - sig/claude_agent_sdk/types/option_values.rbs
195
+ - sig/claude_agent_sdk/types/options.rbs
196
+ - sig/claude_agent_sdk/types/permissions.rbs
197
+ - sig/claude_agent_sdk/types/sessions.rbs
198
+ - sig/manifest.yaml
178
199
  homepage: https://github.com/ya-luotao/claude-agent-sdk-ruby
179
200
  licenses:
180
201
  - MIT