simple_acp 0.0.1

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 (80) hide show
  1. checksums.yaml +7 -0
  2. data/.envrc +1 -0
  3. data/CHANGELOG.md +5 -0
  4. data/COMMITS.md +196 -0
  5. data/LICENSE.txt +21 -0
  6. data/README.md +385 -0
  7. data/Rakefile +13 -0
  8. data/docs/api/client-base.md +383 -0
  9. data/docs/api/index.md +159 -0
  10. data/docs/api/models.md +286 -0
  11. data/docs/api/server-base.md +379 -0
  12. data/docs/api/storage.md +347 -0
  13. data/docs/assets/images/simple_acp.jpg +0 -0
  14. data/docs/client/index.md +279 -0
  15. data/docs/client/sessions.md +324 -0
  16. data/docs/client/streaming.md +345 -0
  17. data/docs/client/sync-async.md +308 -0
  18. data/docs/core-concepts/agents.md +253 -0
  19. data/docs/core-concepts/events.md +337 -0
  20. data/docs/core-concepts/index.md +147 -0
  21. data/docs/core-concepts/messages.md +211 -0
  22. data/docs/core-concepts/runs.md +278 -0
  23. data/docs/core-concepts/sessions.md +281 -0
  24. data/docs/examples.md +659 -0
  25. data/docs/getting-started/configuration.md +166 -0
  26. data/docs/getting-started/index.md +62 -0
  27. data/docs/getting-started/installation.md +95 -0
  28. data/docs/getting-started/quick-start.md +189 -0
  29. data/docs/index.md +119 -0
  30. data/docs/server/creating-agents.md +360 -0
  31. data/docs/server/http-endpoints.md +411 -0
  32. data/docs/server/index.md +218 -0
  33. data/docs/server/multi-turn.md +329 -0
  34. data/docs/server/streaming.md +315 -0
  35. data/docs/storage/custom.md +414 -0
  36. data/docs/storage/index.md +176 -0
  37. data/docs/storage/memory.md +198 -0
  38. data/docs/storage/postgresql.md +350 -0
  39. data/docs/storage/redis.md +287 -0
  40. data/examples/01_basic/client.rb +88 -0
  41. data/examples/01_basic/server.rb +100 -0
  42. data/examples/02_async_execution/client.rb +107 -0
  43. data/examples/02_async_execution/server.rb +56 -0
  44. data/examples/03_run_management/client.rb +115 -0
  45. data/examples/03_run_management/server.rb +84 -0
  46. data/examples/04_rich_messages/client.rb +160 -0
  47. data/examples/04_rich_messages/server.rb +180 -0
  48. data/examples/05_await_resume/client.rb +164 -0
  49. data/examples/05_await_resume/server.rb +114 -0
  50. data/examples/06_agent_metadata/client.rb +188 -0
  51. data/examples/06_agent_metadata/server.rb +192 -0
  52. data/examples/README.md +252 -0
  53. data/examples/run_demo.sh +137 -0
  54. data/lib/simple_acp/client/base.rb +448 -0
  55. data/lib/simple_acp/client/sse.rb +141 -0
  56. data/lib/simple_acp/models/agent_manifest.rb +129 -0
  57. data/lib/simple_acp/models/await.rb +123 -0
  58. data/lib/simple_acp/models/base.rb +147 -0
  59. data/lib/simple_acp/models/errors.rb +102 -0
  60. data/lib/simple_acp/models/events.rb +256 -0
  61. data/lib/simple_acp/models/message.rb +235 -0
  62. data/lib/simple_acp/models/message_part.rb +225 -0
  63. data/lib/simple_acp/models/metadata.rb +161 -0
  64. data/lib/simple_acp/models/run.rb +298 -0
  65. data/lib/simple_acp/models/session.rb +137 -0
  66. data/lib/simple_acp/models/types.rb +210 -0
  67. data/lib/simple_acp/server/agent.rb +116 -0
  68. data/lib/simple_acp/server/app.rb +264 -0
  69. data/lib/simple_acp/server/base.rb +510 -0
  70. data/lib/simple_acp/server/context.rb +210 -0
  71. data/lib/simple_acp/server/falcon_runner.rb +61 -0
  72. data/lib/simple_acp/storage/base.rb +129 -0
  73. data/lib/simple_acp/storage/memory.rb +108 -0
  74. data/lib/simple_acp/storage/postgresql.rb +233 -0
  75. data/lib/simple_acp/storage/redis.rb +178 -0
  76. data/lib/simple_acp/version.rb +5 -0
  77. data/lib/simple_acp.rb +91 -0
  78. data/mkdocs.yml +152 -0
  79. data/sig/simple_acp.rbs +4 -0
  80. metadata +418 -0
@@ -0,0 +1,383 @@
1
+ # Client::Base
2
+
3
+ HTTP client for communicating with ACP servers.
4
+
5
+ ## Class: SimpleAcp::Client::Base
6
+
7
+ ### Constructor
8
+
9
+ ```ruby
10
+ SimpleAcp::Client::Base.new(base_url:, timeout: 30, headers: {})
11
+ ```
12
+
13
+ **Parameters:**
14
+
15
+ | Name | Type | Default | Description |
16
+ |------|------|---------|-------------|
17
+ | `base_url` | `String` | required | Server URL |
18
+ | `timeout` | `Integer` | `30` | Request timeout in seconds |
19
+ | `headers` | `Hash` | `{}` | Custom headers |
20
+
21
+ **Example:**
22
+
23
+ ```ruby
24
+ client = SimpleAcp::Client::Base.new(
25
+ base_url: "http://localhost:8000",
26
+ timeout: 60,
27
+ headers: { "Authorization" => "Bearer token" }
28
+ )
29
+ ```
30
+
31
+ ---
32
+
33
+ ### Discovery Methods
34
+
35
+ #### #ping
36
+
37
+ Check server health.
38
+
39
+ ```ruby
40
+ client.ping
41
+ ```
42
+
43
+ **Returns:** `Boolean`
44
+
45
+ **Example:**
46
+
47
+ ```ruby
48
+ if client.ping
49
+ puts "Server is healthy"
50
+ end
51
+ ```
52
+
53
+ ---
54
+
55
+ #### #agents
56
+
57
+ List all available agents.
58
+
59
+ ```ruby
60
+ client.agents
61
+ ```
62
+
63
+ **Returns:** `Models::Types::AgentList`
64
+
65
+ **Example:**
66
+
67
+ ```ruby
68
+ response = client.agents
69
+ response.agents.each do |agent|
70
+ puts "#{agent.name}: #{agent.description}"
71
+ end
72
+ ```
73
+
74
+ ---
75
+
76
+ #### #agent
77
+
78
+ Get a specific agent's manifest.
79
+
80
+ ```ruby
81
+ client.agent(name)
82
+ ```
83
+
84
+ **Parameters:**
85
+
86
+ | Name | Type | Description |
87
+ |------|------|-------------|
88
+ | `name` | `String` | Agent name |
89
+
90
+ **Returns:** `Models::AgentManifest`
91
+
92
+ **Raises:** `SimpleAcp::Error` if not found
93
+
94
+ ---
95
+
96
+ ### Execution Methods
97
+
98
+ #### #run_sync
99
+
100
+ Execute an agent and wait for completion.
101
+
102
+ ```ruby
103
+ client.run_sync(agent:, input:)
104
+ ```
105
+
106
+ **Parameters:**
107
+
108
+ | Name | Type | Description |
109
+ |------|------|-------------|
110
+ | `agent` | `String` | Agent name |
111
+ | `input` | `Array<Message>` or `String` | Input messages |
112
+
113
+ **Returns:** `Models::Run`
114
+
115
+ **Example:**
116
+
117
+ ```ruby
118
+ run = client.run_sync(
119
+ agent: "echo",
120
+ input: [SimpleAcp::Models::Message.user("Hello")]
121
+ )
122
+
123
+ # String input is auto-converted
124
+ run = client.run_sync(agent: "echo", input: "Hello")
125
+ ```
126
+
127
+ ---
128
+
129
+ #### #run_async
130
+
131
+ Start an agent execution without waiting.
132
+
133
+ ```ruby
134
+ client.run_async(agent:, input:)
135
+ ```
136
+
137
+ **Parameters:** Same as `#run_sync`
138
+
139
+ **Returns:** `Models::Run` (status will be `in_progress` or `created`)
140
+
141
+ ---
142
+
143
+ #### #run_stream
144
+
145
+ Execute an agent with streaming events.
146
+
147
+ ```ruby
148
+ client.run_stream(agent:, input:, &block)
149
+ ```
150
+
151
+ **Parameters:**
152
+
153
+ | Name | Type | Description |
154
+ |------|------|-------------|
155
+ | `agent` | `String` | Agent name |
156
+ | `input` | `Array<Message>` or `String` | Input messages |
157
+ | `&block` | `Block` | Event handler |
158
+
159
+ **Returns:** `Models::Run`
160
+
161
+ **Example:**
162
+
163
+ ```ruby
164
+ client.run_stream(agent: "chat", input: "Hello") do |event|
165
+ case event
166
+ when SimpleAcp::Models::RunStartedEvent
167
+ puts "Started!"
168
+ when SimpleAcp::Models::MessagePartEvent
169
+ print event.part.content
170
+ when SimpleAcp::Models::RunCompletedEvent
171
+ puts "\nDone!"
172
+ end
173
+ end
174
+ ```
175
+
176
+ ---
177
+
178
+ ### Run Management
179
+
180
+ #### #run_status
181
+
182
+ Get current status of a run.
183
+
184
+ ```ruby
185
+ client.run_status(run_id)
186
+ ```
187
+
188
+ **Parameters:**
189
+
190
+ | Name | Type | Description |
191
+ |------|------|-------------|
192
+ | `run_id` | `String` | Run ID |
193
+
194
+ **Returns:** `Models::Run`
195
+
196
+ ---
197
+
198
+ #### #run_events
199
+
200
+ Get events for a run.
201
+
202
+ ```ruby
203
+ client.run_events(run_id, limit: 100, offset: 0)
204
+ ```
205
+
206
+ **Parameters:**
207
+
208
+ | Name | Type | Default | Description |
209
+ |------|------|---------|-------------|
210
+ | `run_id` | `String` | required | Run ID |
211
+ | `limit` | `Integer` | `100` | Max events |
212
+ | `offset` | `Integer` | `0` | Skip count |
213
+
214
+ **Returns:** `Array<Event>`
215
+
216
+ ---
217
+
218
+ #### #run_cancel
219
+
220
+ Cancel an in-progress run.
221
+
222
+ ```ruby
223
+ client.run_cancel(run_id)
224
+ ```
225
+
226
+ **Parameters:**
227
+
228
+ | Name | Type | Description |
229
+ |------|------|-------------|
230
+ | `run_id` | `String` | Run ID |
231
+
232
+ **Returns:** `Models::Run`
233
+
234
+ ---
235
+
236
+ ### Resume Methods
237
+
238
+ #### #run_resume_sync
239
+
240
+ Resume an awaiting run synchronously.
241
+
242
+ ```ruby
243
+ client.run_resume_sync(run_id:, await_resume:)
244
+ ```
245
+
246
+ **Parameters:**
247
+
248
+ | Name | Type | Description |
249
+ |------|------|-------------|
250
+ | `run_id` | `String` | Run to resume |
251
+ | `await_resume` | `AwaitResume` | Resume payload |
252
+
253
+ **Returns:** `Models::Run`
254
+
255
+ **Example:**
256
+
257
+ ```ruby
258
+ run = client.run_resume_sync(
259
+ run_id: run.run_id,
260
+ await_resume: SimpleAcp::Models::MessageAwaitResume.new(
261
+ message: SimpleAcp::Models::Message.user("My answer")
262
+ )
263
+ )
264
+ ```
265
+
266
+ ---
267
+
268
+ #### #run_resume_stream
269
+
270
+ Resume an awaiting run with streaming.
271
+
272
+ ```ruby
273
+ client.run_resume_stream(run_id:, await_resume:, &block)
274
+ ```
275
+
276
+ **Parameters:** Same as `#run_resume_sync` plus event block
277
+
278
+ **Returns:** `Models::Run`
279
+
280
+ ---
281
+
282
+ ### Session Management
283
+
284
+ #### #use_session
285
+
286
+ Set the session for subsequent requests.
287
+
288
+ ```ruby
289
+ client.use_session(session_id)
290
+ ```
291
+
292
+ **Parameters:**
293
+
294
+ | Name | Type | Description |
295
+ |------|------|-------------|
296
+ | `session_id` | `String` | Session ID to use |
297
+
298
+ **Returns:** `self`
299
+
300
+ **Example:**
301
+
302
+ ```ruby
303
+ client.use_session("conversation-123")
304
+ client.run_sync(agent: "chat", input: "Hello")
305
+ client.run_sync(agent: "chat", input: "Continue...")
306
+ ```
307
+
308
+ ---
309
+
310
+ #### #clear_session
311
+
312
+ Clear the current session.
313
+
314
+ ```ruby
315
+ client.clear_session
316
+ ```
317
+
318
+ **Returns:** `self`
319
+
320
+ ---
321
+
322
+ #### #session_id
323
+
324
+ Get the current session ID.
325
+
326
+ ```ruby
327
+ client.session_id
328
+ ```
329
+
330
+ **Returns:** `String` or `nil`
331
+
332
+ ---
333
+
334
+ #### #session
335
+
336
+ Get session information.
337
+
338
+ ```ruby
339
+ client.session(session_id)
340
+ ```
341
+
342
+ **Parameters:**
343
+
344
+ | Name | Type | Description |
345
+ |------|------|-------------|
346
+ | `session_id` | `String` | Session ID |
347
+
348
+ **Returns:** `Models::Session`
349
+
350
+ ---
351
+
352
+ ### Properties
353
+
354
+ | Property | Type | Description |
355
+ |----------|------|-------------|
356
+ | `base_url` | `String` | Server URL |
357
+ | `timeout` | `Integer` | Request timeout |
358
+ | `session_id` | `String` | Current session |
359
+
360
+ ---
361
+
362
+ ## Error Handling
363
+
364
+ ```ruby
365
+ begin
366
+ run = client.run_sync(agent: "unknown", input: "test")
367
+ rescue SimpleAcp::Error => e
368
+ puts "ACP Error: #{e.message}"
369
+ rescue Faraday::TimeoutError
370
+ puts "Request timed out"
371
+ rescue Faraday::ConnectionFailed
372
+ puts "Connection failed"
373
+ end
374
+ ```
375
+
376
+ ---
377
+
378
+ ## See Also
379
+
380
+ - [Client Guide](../client/index.md)
381
+ - [Sync & Async](../client/sync-async.md)
382
+ - [Streaming](../client/streaming.md)
383
+ - [Sessions](../client/sessions.md)
data/docs/api/index.md ADDED
@@ -0,0 +1,159 @@
1
+ # API Reference
2
+
3
+ Complete API documentation for SimpleAcp classes and modules.
4
+
5
+ ## Overview
6
+
7
+ SimpleAcp is organized into these main namespaces:
8
+
9
+ ```
10
+ SimpleAcp
11
+ ├── Server
12
+ │ ├── Base # Main server class
13
+ │ ├── App # Roda HTTP application
14
+ │ ├── Context # Execution context
15
+ │ └── Agent # Agent wrapper
16
+ ├── Client
17
+ │ ├── Base # HTTP client
18
+ │ └── SSE # SSE parsing
19
+ ├── Models
20
+ │ ├── Message # Messages
21
+ │ ├── MessagePart # Message content
22
+ │ ├── Run # Run execution
23
+ │ ├── Session # Sessions
24
+ │ ├── Events # Event types
25
+ │ └── ... # Other models
26
+ └── Storage
27
+ ├── Base # Abstract interface
28
+ ├── Memory # In-memory storage
29
+ ├── Redis # Redis storage
30
+ └── PostgreSQL # PostgreSQL storage
31
+ ```
32
+
33
+ ## Quick Links
34
+
35
+ <div class="grid cards" markdown>
36
+
37
+ - :material-server:{ .lg .middle } **Server::Base**
38
+
39
+ ---
40
+
41
+ Main server class for hosting agents
42
+
43
+ [:octicons-arrow-right-24: Server::Base](server-base.md)
44
+
45
+ - :material-web:{ .lg .middle } **Client::Base**
46
+
47
+ ---
48
+
49
+ HTTP client for ACP servers
50
+
51
+ [:octicons-arrow-right-24: Client::Base](client-base.md)
52
+
53
+ - :material-cube:{ .lg .middle } **Models**
54
+
55
+ ---
56
+
57
+ Data models for messages, runs, sessions
58
+
59
+ [:octicons-arrow-right-24: Models](models.md)
60
+
61
+ - :material-database:{ .lg .middle } **Storage**
62
+
63
+ ---
64
+
65
+ Storage backend interface
66
+
67
+ [:octicons-arrow-right-24: Storage](storage.md)
68
+
69
+ </div>
70
+
71
+ ## Configuration
72
+
73
+ ### Global Configuration
74
+
75
+ ```ruby
76
+ SimpleAcp.configure do |config|
77
+ config.logger = Logger.new(STDOUT)
78
+ end
79
+ ```
80
+
81
+ ### Exception Classes
82
+
83
+ ```ruby
84
+ SimpleAcp::Error # Base exception class
85
+ SimpleAcp::ConfigError # Configuration errors
86
+ SimpleAcp::ValidationError # Input validation errors
87
+ ```
88
+
89
+ ## Constants
90
+
91
+ ```ruby
92
+ SimpleAcp::VERSION # Gem version string
93
+ ```
94
+
95
+ ## Module Methods
96
+
97
+ ### SimpleAcp.configure
98
+
99
+ Configure global settings.
100
+
101
+ ```ruby
102
+ SimpleAcp.configure do |config|
103
+ # Configuration options
104
+ end
105
+ ```
106
+
107
+ ## Architecture
108
+
109
+ ```mermaid
110
+ classDiagram
111
+ class Server {
112
+ +agents
113
+ +storage
114
+ +agent()
115
+ +register()
116
+ +run_sync()
117
+ +run_async()
118
+ +run_stream()
119
+ }
120
+
121
+ class Client {
122
+ +base_url
123
+ +ping()
124
+ +agents()
125
+ +run_sync()
126
+ +run_stream()
127
+ }
128
+
129
+ class Storage {
130
+ +get_run()
131
+ +save_run()
132
+ +get_session()
133
+ +save_session()
134
+ }
135
+
136
+ class Run {
137
+ +run_id
138
+ +status
139
+ +output
140
+ }
141
+
142
+ class Session {
143
+ +id
144
+ +history
145
+ +state
146
+ }
147
+
148
+ Server --> Storage
149
+ Server --> Run
150
+ Server --> Session
151
+ Client --> Run
152
+ ```
153
+
154
+ ## Detailed Documentation
155
+
156
+ - [Server::Base](server-base.md) - Server class API
157
+ - [Client::Base](client-base.md) - Client class API
158
+ - [Models](models.md) - All model classes
159
+ - [Storage](storage.md) - Storage interface