llm.rb 9.0.0 → 11.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 (59) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +182 -4
  3. data/README.md +194 -42
  4. data/data/anthropic.json +278 -258
  5. data/data/bedrock.json +1288 -1561
  6. data/data/deepseek.json +38 -38
  7. data/data/google.json +656 -579
  8. data/data/openai.json +860 -818
  9. data/data/xai.json +243 -552
  10. data/data/zai.json +168 -168
  11. data/lib/llm/a2a/card/capabilities.rb +41 -0
  12. data/lib/llm/a2a/card/interface.rb +34 -0
  13. data/lib/llm/a2a/card/provider.rb +27 -0
  14. data/lib/llm/a2a/card/skill.rb +68 -0
  15. data/lib/llm/a2a/card.rb +144 -0
  16. data/lib/llm/a2a/error.rb +49 -0
  17. data/lib/llm/a2a/notifications.rb +53 -0
  18. data/lib/llm/a2a/tasks.rb +55 -0
  19. data/lib/llm/a2a/transport/http.rb +131 -0
  20. data/lib/llm/a2a.rb +452 -0
  21. data/lib/llm/active_record/acts_as_agent.rb +20 -9
  22. data/lib/llm/active_record/acts_as_llm.rb +4 -4
  23. data/lib/llm/active_record.rb +1 -6
  24. data/lib/llm/agent.rb +96 -71
  25. data/lib/llm/buffer.rb +1 -2
  26. data/lib/llm/context.rb +77 -50
  27. data/lib/llm/file.rb +7 -0
  28. data/lib/llm/function/call_task.rb +46 -0
  29. data/lib/llm/function.rb +28 -2
  30. data/lib/llm/mcp/transport/http.rb +5 -18
  31. data/lib/llm/mcp/transport/stdio.rb +7 -0
  32. data/lib/llm/mcp.rb +20 -17
  33. data/lib/llm/message.rb +1 -1
  34. data/lib/llm/object/kernel.rb +1 -1
  35. data/lib/llm/provider.rb +9 -9
  36. data/lib/llm/providers/anthropic/stream_parser.rb +2 -2
  37. data/lib/llm/providers/bedrock/stream_parser.rb +2 -2
  38. data/lib/llm/providers/google/stream_parser.rb +2 -2
  39. data/lib/llm/providers/openai/responses/stream_parser.rb +2 -2
  40. data/lib/llm/providers/openai/stream_parser.rb +2 -2
  41. data/lib/llm/response.rb +1 -1
  42. data/lib/llm/schema.rb +11 -0
  43. data/lib/llm/sequel/agent.rb +19 -9
  44. data/lib/llm/sequel/plugin.rb +9 -13
  45. data/lib/llm/stream.rb +11 -36
  46. data/lib/llm/tool/param.rb +1 -8
  47. data/lib/llm/tool.rb +57 -27
  48. data/lib/llm/tracer.rb +1 -1
  49. data/lib/llm/transport/http.rb +1 -1
  50. data/lib/llm/transport/stream_decoder.rb +6 -3
  51. data/lib/llm/transport/utils.rb +35 -0
  52. data/lib/llm/transport.rb +1 -0
  53. data/lib/llm/utils.rb +73 -0
  54. data/lib/llm/version.rb +1 -1
  55. data/lib/llm.rb +24 -4
  56. data/llm.gemspec +16 -1
  57. metadata +29 -5
  58. data/lib/llm/bot.rb +0 -3
  59. data/lib/llm/mcp/transport/http/event_handler.rb +0 -68
data/data/zai.json CHANGED
@@ -8,6 +8,40 @@
8
8
  "name": "Z.AI",
9
9
  "doc": "https://docs.z.ai/guides/overview/pricing",
10
10
  "models": {
11
+ "glm-5.1": {
12
+ "id": "glm-5.1",
13
+ "name": "GLM-5.1",
14
+ "family": "glm",
15
+ "attachment": false,
16
+ "reasoning": true,
17
+ "tool_call": true,
18
+ "interleaved": {
19
+ "field": "reasoning_content"
20
+ },
21
+ "structured_output": true,
22
+ "temperature": true,
23
+ "release_date": "2026-03-27",
24
+ "last_updated": "2026-03-27",
25
+ "modalities": {
26
+ "input": [
27
+ "text"
28
+ ],
29
+ "output": [
30
+ "text"
31
+ ]
32
+ },
33
+ "open_weights": false,
34
+ "limit": {
35
+ "context": 200000,
36
+ "output": 131072
37
+ },
38
+ "cost": {
39
+ "input": 1.4,
40
+ "output": 4.4,
41
+ "cache_read": 0.26,
42
+ "cache_write": 0
43
+ }
44
+ },
11
45
  "glm-5v-turbo": {
12
46
  "id": "glm-5v-turbo",
13
47
  "name": "GLM-5V-Turbo",
@@ -33,31 +67,28 @@
33
67
  ]
34
68
  },
35
69
  "open_weights": false,
70
+ "limit": {
71
+ "context": 200000,
72
+ "output": 131072
73
+ },
36
74
  "cost": {
37
75
  "input": 1.2,
38
76
  "output": 4,
39
77
  "cache_read": 0.24,
40
78
  "cache_write": 0
41
- },
42
- "limit": {
43
- "context": 200000,
44
- "output": 131072
45
79
  }
46
80
  },
47
- "glm-4.7": {
48
- "id": "glm-4.7",
49
- "name": "GLM-4.7",
50
- "family": "glm",
81
+ "glm-4.7-flashx": {
82
+ "id": "glm-4.7-flashx",
83
+ "name": "GLM-4.7-FlashX",
84
+ "family": "glm-flash",
51
85
  "attachment": false,
52
86
  "reasoning": true,
53
87
  "tool_call": true,
54
- "interleaved": {
55
- "field": "reasoning_content"
56
- },
57
88
  "temperature": true,
58
89
  "knowledge": "2025-04",
59
- "release_date": "2025-12-22",
60
- "last_updated": "2025-12-22",
90
+ "release_date": "2026-01-19",
91
+ "last_updated": "2026-01-19",
61
92
  "modalities": {
62
93
  "input": [
63
94
  "text"
@@ -67,30 +98,28 @@
67
98
  ]
68
99
  },
69
100
  "open_weights": true,
70
- "cost": {
71
- "input": 0.6,
72
- "output": 2.2,
73
- "cache_read": 0.11,
74
- "cache_write": 0
75
- },
76
101
  "limit": {
77
- "context": 204800,
102
+ "context": 200000,
78
103
  "output": 131072
104
+ },
105
+ "cost": {
106
+ "input": 0.07,
107
+ "output": 0.4,
108
+ "cache_read": 0.01,
109
+ "cache_write": 0
79
110
  }
80
111
  },
81
- "glm-5": {
82
- "id": "glm-5",
83
- "name": "GLM-5",
84
- "family": "glm",
112
+ "glm-4.5-air": {
113
+ "id": "glm-4.5-air",
114
+ "name": "GLM-4.5-Air",
115
+ "family": "glm-air",
85
116
  "attachment": false,
86
117
  "reasoning": true,
87
118
  "tool_call": true,
88
- "interleaved": {
89
- "field": "reasoning_content"
90
- },
91
119
  "temperature": true,
92
- "release_date": "2026-02-11",
93
- "last_updated": "2026-02-11",
120
+ "knowledge": "2025-04",
121
+ "release_date": "2025-07-28",
122
+ "last_updated": "2025-07-28",
94
123
  "modalities": {
95
124
  "input": [
96
125
  "text"
@@ -100,20 +129,51 @@
100
129
  ]
101
130
  },
102
131
  "open_weights": true,
132
+ "limit": {
133
+ "context": 131072,
134
+ "output": 98304
135
+ },
103
136
  "cost": {
104
- "input": 1,
105
- "output": 3.2,
106
- "cache_read": 0.2,
137
+ "input": 0.2,
138
+ "output": 1.1,
139
+ "cache_read": 0.03,
107
140
  "cache_write": 0
141
+ }
142
+ },
143
+ "glm-4.5v": {
144
+ "id": "glm-4.5v",
145
+ "name": "GLM-4.5V",
146
+ "family": "glm",
147
+ "attachment": true,
148
+ "reasoning": true,
149
+ "tool_call": true,
150
+ "temperature": true,
151
+ "knowledge": "2025-04",
152
+ "release_date": "2025-08-11",
153
+ "last_updated": "2025-08-11",
154
+ "modalities": {
155
+ "input": [
156
+ "text",
157
+ "image",
158
+ "video"
159
+ ],
160
+ "output": [
161
+ "text"
162
+ ]
108
163
  },
164
+ "open_weights": true,
109
165
  "limit": {
110
- "context": 204800,
111
- "output": 131072
166
+ "context": 64000,
167
+ "output": 16384
168
+ },
169
+ "cost": {
170
+ "input": 0.6,
171
+ "output": 1.8
112
172
  }
113
173
  },
114
- "glm-4.7-flashx": {
115
- "id": "glm-4.7-flashx",
116
- "name": "GLM-4.7-FlashX",
174
+ "glm-4.7-flash": {
175
+ "id": "glm-4.7-flash",
176
+ "name": "GLM-4.7-Flash",
117
177
  "family": "glm-flash",
118
178
  "attachment": false,
119
179
  "reasoning": true,
@@ -131,31 +191,28 @@
131
191
  ]
132
192
  },
133
193
  "open_weights": true,
134
- "cost": {
135
- "input": 0.07,
136
- "output": 0.4,
137
- "cache_read": 0.01,
138
- "cache_write": 0
139
- },
140
194
  "limit": {
141
195
  "context": 200000,
142
196
  "output": 131072
197
+ },
198
+ "cost": {
199
+ "input": 0,
200
+ "output": 0,
201
+ "cache_read": 0,
202
+ "cache_write": 0
143
203
  }
144
204
  },
145
- "glm-5.1": {
146
- "id": "glm-5.1",
147
- "name": "GLM-5.1",
205
+ "glm-4.6": {
206
+ "id": "glm-4.6",
207
+ "name": "GLM-4.6",
148
208
  "family": "glm",
149
209
  "attachment": false,
150
210
  "reasoning": true,
151
211
  "tool_call": true,
152
- "interleaved": {
153
- "field": "reasoning_content"
154
- },
155
- "structured_output": true,
156
212
  "temperature": true,
157
- "release_date": "2026-03-27",
158
- "last_updated": "2026-03-27",
213
+ "knowledge": "2025-04",
214
+ "release_date": "2025-09-30",
215
+ "last_updated": "2025-09-30",
159
216
  "modalities": {
160
217
  "input": [
161
218
  "text"
@@ -164,16 +221,16 @@
164
221
  "text"
165
222
  ]
166
223
  },
167
- "open_weights": false,
168
- "cost": {
169
- "input": 1.4,
170
- "output": 4.4,
171
- "cache_read": 0.26,
172
- "cache_write": 0
173
- },
224
+ "open_weights": true,
174
225
  "limit": {
175
- "context": 200000,
226
+ "context": 204800,
176
227
  "output": 131072
228
+ },
229
+ "cost": {
230
+ "input": 0.6,
231
+ "output": 2.2,
232
+ "cache_read": 0.11,
233
+ "cache_write": 0
177
234
  }
178
235
  },
179
236
  "glm-4.5": {
@@ -196,21 +253,21 @@
196
253
  ]
197
254
  },
198
255
  "open_weights": true,
256
+ "limit": {
257
+ "context": 131072,
258
+ "output": 98304
259
+ },
199
260
  "cost": {
200
261
  "input": 0.6,
201
262
  "output": 2.2,
202
263
  "cache_read": 0.11,
203
264
  "cache_write": 0
204
- },
205
- "limit": {
206
- "context": 131072,
207
- "output": 98304
208
265
  }
209
266
  },
210
- "glm-4.5-air": {
211
- "id": "glm-4.5-air",
212
- "name": "GLM-4.5-Air",
213
- "family": "glm-air",
267
+ "glm-4.5-flash": {
268
+ "id": "glm-4.5-flash",
269
+ "name": "GLM-4.5-Flash",
270
+ "family": "glm-flash",
214
271
  "attachment": false,
215
272
  "reasoning": true,
216
273
  "tool_call": true,
@@ -227,15 +284,15 @@
227
284
  ]
228
285
  },
229
286
  "open_weights": true,
230
- "cost": {
231
- "input": 0.2,
232
- "output": 1.1,
233
- "cache_read": 0.03,
234
- "cache_write": 0
235
- },
236
287
  "limit": {
237
288
  "context": 131072,
238
289
  "output": 98304
290
+ },
291
+ "cost": {
292
+ "input": 0,
293
+ "output": 0,
294
+ "cache_read": 0,
295
+ "cache_write": 0
239
296
  }
240
297
  },
241
298
  "glm-5-turbo": {
@@ -261,59 +318,64 @@
261
318
  ]
262
319
  },
263
320
  "open_weights": false,
321
+ "limit": {
322
+ "context": 200000,
323
+ "output": 131072
324
+ },
264
325
  "cost": {
265
326
  "input": 1.2,
266
327
  "output": 4,
267
328
  "cache_read": 0.24,
268
329
  "cache_write": 0
269
- },
270
- "limit": {
271
- "context": 200000,
272
- "output": 131072
273
330
  }
274
331
  },
275
- "glm-4.5v": {
276
- "id": "glm-4.5v",
277
- "name": "GLM-4.5V",
332
+ "glm-4.7": {
333
+ "id": "glm-4.7",
334
+ "name": "GLM-4.7",
278
335
  "family": "glm",
279
- "attachment": true,
336
+ "attachment": false,
280
337
  "reasoning": true,
281
338
  "tool_call": true,
339
+ "interleaved": {
340
+ "field": "reasoning_content"
341
+ },
282
342
  "temperature": true,
283
343
  "knowledge": "2025-04",
284
- "release_date": "2025-08-11",
285
- "last_updated": "2025-08-11",
344
+ "release_date": "2025-12-22",
345
+ "last_updated": "2025-12-22",
286
346
  "modalities": {
287
347
  "input": [
288
- "text",
289
- "image",
290
- "video"
348
+ "text"
291
349
  ],
292
350
  "output": [
293
351
  "text"
294
352
  ]
295
353
  },
296
354
  "open_weights": true,
355
+ "limit": {
356
+ "context": 204800,
357
+ "output": 131072
358
+ },
297
359
  "cost": {
298
360
  "input": 0.6,
299
- "output": 1.8
300
- },
301
- "limit": {
302
- "context": 64000,
303
- "output": 16384
361
+ "output": 2.2,
362
+ "cache_read": 0.11,
363
+ "cache_write": 0
304
364
  }
305
365
  },
306
- "glm-4.6": {
307
- "id": "glm-4.6",
308
- "name": "GLM-4.6",
366
+ "glm-5": {
367
+ "id": "glm-5",
368
+ "name": "GLM-5",
309
369
  "family": "glm",
310
370
  "attachment": false,
311
371
  "reasoning": true,
312
372
  "tool_call": true,
373
+ "interleaved": {
374
+ "field": "reasoning_content"
375
+ },
313
376
  "temperature": true,
314
- "knowledge": "2025-04",
315
- "release_date": "2025-09-30",
316
- "last_updated": "2025-09-30",
377
+ "release_date": "2026-02-11",
378
+ "last_updated": "2026-02-11",
317
379
  "modalities": {
318
380
  "input": [
319
381
  "text"
@@ -323,15 +385,15 @@
323
385
  ]
324
386
  },
325
387
  "open_weights": true,
326
- "cost": {
327
- "input": 0.6,
328
- "output": 2.2,
329
- "cache_read": 0.11,
330
- "cache_write": 0
331
- },
332
388
  "limit": {
333
389
  "context": 204800,
334
390
  "output": 131072
391
+ },
392
+ "cost": {
393
+ "input": 1,
394
+ "output": 3.2,
395
+ "cache_read": 0.2,
396
+ "cache_write": 0
335
397
  }
336
398
  },
337
399
  "glm-4.6v": {
@@ -356,75 +418,13 @@
356
418
  ]
357
419
  },
358
420
  "open_weights": true,
359
- "cost": {
360
- "input": 0.3,
361
- "output": 0.9
362
- },
363
421
  "limit": {
364
422
  "context": 128000,
365
423
  "output": 32768
366
- }
367
- },
368
- "glm-4.5-flash": {
369
- "id": "glm-4.5-flash",
370
- "name": "GLM-4.5-Flash",
371
- "family": "glm-flash",
372
- "attachment": false,
373
- "reasoning": true,
374
- "tool_call": true,
375
- "temperature": true,
376
- "knowledge": "2025-04",
377
- "release_date": "2025-07-28",
378
- "last_updated": "2025-07-28",
379
- "modalities": {
380
- "input": [
381
- "text"
382
- ],
383
- "output": [
384
- "text"
385
- ]
386
424
  },
387
- "open_weights": true,
388
- "cost": {
389
- "input": 0,
390
- "output": 0,
391
- "cache_read": 0,
392
- "cache_write": 0
393
- },
394
- "limit": {
395
- "context": 131072,
396
- "output": 98304
397
- }
398
- },
399
- "glm-4.7-flash": {
400
- "id": "glm-4.7-flash",
401
- "name": "GLM-4.7-Flash",
402
- "family": "glm-flash",
403
- "attachment": false,
404
- "reasoning": true,
405
- "tool_call": true,
406
- "temperature": true,
407
- "knowledge": "2025-04",
408
- "release_date": "2026-01-19",
409
- "last_updated": "2026-01-19",
410
- "modalities": {
411
- "input": [
412
- "text"
413
- ],
414
- "output": [
415
- "text"
416
- ]
417
- },
418
- "open_weights": true,
419
425
  "cost": {
420
- "input": 0,
421
- "output": 0,
422
- "cache_read": 0,
423
- "cache_write": 0
424
- },
425
- "limit": {
426
- "context": 200000,
427
- "output": 131072
426
+ "input": 0.3,
427
+ "output": 0.9
428
428
  }
429
429
  }
430
430
  }
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ class LLM::A2A::Card
4
+ ##
5
+ # Represents the agent's optional capabilities.
6
+ class Capabilities
7
+ ##
8
+ # @param [Hash] data
9
+ def initialize(data)
10
+ @data = LLM::Object.from(data)
11
+ end
12
+
13
+ ##
14
+ # Returns whether the agent supports streaming.
15
+ # @return [Boolean]
16
+ def streaming
17
+ @data.streaming == true
18
+ end
19
+
20
+ ##
21
+ # Returns whether the agent supports push notifications.
22
+ # @return [Boolean]
23
+ def push_notifications
24
+ @data.pushNotifications == true
25
+ end
26
+
27
+ ##
28
+ # Returns whether the agent exposes an extended card.
29
+ # @return [Boolean]
30
+ def extended_agent_card
31
+ @data.extendedAgentCard == true
32
+ end
33
+
34
+ ##
35
+ # Returns the declared agent extensions.
36
+ # @return [Array<LLM::Object>]
37
+ def extensions
38
+ @extensions ||= (@data.extensions || []).map { LLM::Object.from(_1) }
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ class LLM::A2A::Card
4
+ ##
5
+ # Represents a protocol interface supported by the agent.
6
+ class Interface
7
+ ##
8
+ # @param [Hash] data
9
+ def initialize(data)
10
+ @data = LLM::Object.from(data)
11
+ end
12
+
13
+ ##
14
+ # Returns the interface URL.
15
+ # @return [String]
16
+ def url
17
+ @data.url
18
+ end
19
+
20
+ ##
21
+ # Returns the protocol binding name.
22
+ # @return [String]
23
+ def protocol_binding
24
+ @data.protocolBinding || @data.protocol_binding
25
+ end
26
+
27
+ ##
28
+ # Returns the A2A protocol version.
29
+ # @return [String]
30
+ def protocol_version
31
+ @data.protocolVersion || @data.protocol_version
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ class LLM::A2A::Card
4
+ ##
5
+ # Represents the service provider of an agent.
6
+ class Provider
7
+ ##
8
+ # @param [Hash] data
9
+ def initialize(data)
10
+ @data = LLM::Object.from(data)
11
+ end
12
+
13
+ ##
14
+ # Returns the provider website URL.
15
+ # @return [String]
16
+ def url
17
+ @data.url
18
+ end
19
+
20
+ ##
21
+ # Returns the provider organization name.
22
+ # @return [String]
23
+ def organization
24
+ @data.organization
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ class LLM::A2A::Card
4
+ ##
5
+ # Represents a single skill/capability of an agent.
6
+ class Skill
7
+ ##
8
+ # @param [Hash] data
9
+ def initialize(data)
10
+ @data = LLM::Object.from(data)
11
+ end
12
+
13
+ ##
14
+ # Returns the unique identifier for the skill.
15
+ # @return [String]
16
+ def id
17
+ @data.id
18
+ end
19
+
20
+ ##
21
+ # Returns the human-readable skill name.
22
+ # @return [String]
23
+ def name
24
+ @data.name
25
+ end
26
+
27
+ ##
28
+ # Returns the detailed skill description.
29
+ # @return [String]
30
+ def description
31
+ @data.description
32
+ end
33
+
34
+ ##
35
+ # Returns capability tags for the skill.
36
+ # @return [Array<String>]
37
+ def tags
38
+ @data.tags || []
39
+ end
40
+
41
+ ##
42
+ # Returns example prompts for the skill.
43
+ # @return [Array<String>]
44
+ def examples
45
+ @data.examples || []
46
+ end
47
+
48
+ ##
49
+ # Returns the supported input media types.
50
+ # @return [Array<String>]
51
+ def input_modes
52
+ @data.inputModes || @data.input_modes || []
53
+ end
54
+
55
+ ##
56
+ # Returns the supported output media types.
57
+ # @return [Array<String>]
58
+ def output_modes
59
+ @data.outputModes || @data.output_modes || []
60
+ end
61
+
62
+ ##
63
+ # @return [String]
64
+ def inspect
65
+ "#<#{LLM::Utils.object_id(self)} @id=#{id.inspect} @name=#{name.inspect}>"
66
+ end
67
+ end
68
+ end