Commit 1e14a82
authored
feat(gateway): use native --json-schema for structured output (#68)
* refactor(gateway): remove legacy CLI output format
Remove backwards compatibility for pre-1.0.17 Claude CLI output format.
The project has always used modern Claude CLI versions, so the legacy
`total_tokens_in/out` fields were never needed.
- Remove `total_tokens_in/out` from ClaudeCliOutput interface
- Update cli.ts to only use `usage.input_tokens/output_tokens`
- Update stream.ts to use `usage` object format
- Update all test fixtures to use new format
* feat(gateway): use native --json-schema for structured output
Replace prompt injection approach with Claude CLI's native --json-schema
flag for constrained JSON decoding. This provides model-level guarantees
of valid JSON output.
Changes:
- Add jsonSchema option to ClaudeCliOptions, pass as --json-schema flag
- Handle structured_output field in CLI response (used by --json-schema)
- Add warning log when jsonSchema provided but structured_output missing
- Simplify /generate-object route by removing prompt injection
- Soften "guarantee" language in comments (external to our code)
Type design improvements:
- Extract CliUsageInfo interface for shared CLI usage type
- Add createUsageInfo() for consistent CLI→API usage conversion
- Extract baseRequestSchema to reduce request schema duplication
- Add int().nonnegative() refinements to UsageInfo schema
- Remove unused outputFormat field from ClaudeCliOptions
- Make rawOutput non-nullable in ClaudeCliResult (we throw on failure)
- Document unused maxTokens field (CLI doesn't support it)
Closes #66
* docs: regenerate OpenAPI spec1 parent d3c0259 commit 1e14a82
File tree
11 files changed
+422
-217
lines changed- docs
- packages
- gateway
- __tests__
- integration
- routes
- src
- routes
- sdks/python
11 files changed
+422
-217
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
41 | | - | |
42 | 40 | | |
43 | 41 | | |
44 | 42 | | |
45 | 43 | | |
46 | 44 | | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
47 | 48 | | |
48 | 49 | | |
49 | 50 | | |
| |||
53 | 54 | | |
54 | 55 | | |
55 | 56 | | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | 57 | | |
60 | 58 | | |
61 | | - | |
62 | | - | |
63 | 59 | | |
64 | 60 | | |
65 | 61 | | |
66 | 62 | | |
67 | 63 | | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
68 | 70 | | |
69 | 71 | | |
70 | 72 | | |
| |||
88 | 90 | | |
89 | 91 | | |
90 | 92 | | |
91 | | - | |
| 93 | + | |
| 94 | + | |
92 | 95 | | |
93 | | - | |
| 96 | + | |
| 97 | + | |
94 | 98 | | |
95 | | - | |
| 99 | + | |
| 100 | + | |
96 | 101 | | |
97 | 102 | | |
98 | 103 | | |
| |||
106 | 111 | | |
107 | 112 | | |
108 | 113 | | |
109 | | - | |
| 114 | + | |
| 115 | + | |
110 | 116 | | |
111 | | - | |
| 117 | + | |
| 118 | + | |
112 | 119 | | |
113 | | - | |
| 120 | + | |
| 121 | + | |
114 | 122 | | |
115 | 123 | | |
116 | 124 | | |
| |||
131 | 139 | | |
132 | 140 | | |
133 | 141 | | |
134 | | - | |
| 142 | + | |
| 143 | + | |
135 | 144 | | |
136 | | - | |
| 145 | + | |
| 146 | + | |
137 | 147 | | |
138 | | - | |
| 148 | + | |
| 149 | + | |
139 | 150 | | |
140 | 151 | | |
141 | 152 | | |
| |||
375 | 386 | | |
376 | 387 | | |
377 | 388 | | |
378 | | - | |
379 | | - | |
380 | 389 | | |
381 | 390 | | |
382 | 391 | | |
383 | 392 | | |
384 | 393 | | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
385 | 397 | | |
386 | 398 | | |
387 | 399 | | |
| |||
398 | 410 | | |
399 | 411 | | |
400 | 412 | | |
401 | | - | |
| 413 | + | |
| 414 | + | |
402 | 415 | | |
403 | | - | |
| 416 | + | |
| 417 | + | |
404 | 418 | | |
405 | | - | |
| 419 | + | |
| 420 | + | |
406 | 421 | | |
407 | 422 | | |
408 | 423 | | |
| |||
487 | 502 | | |
488 | 503 | | |
489 | 504 | | |
490 | | - | |
491 | | - | |
492 | | - | |
493 | 505 | | |
494 | 506 | | |
495 | | - | |
496 | | - | |
497 | 507 | | |
498 | 508 | | |
499 | 509 | | |
500 | 510 | | |
501 | 511 | | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
502 | 518 | | |
503 | 519 | | |
504 | 520 | | |
| |||
517 | 533 | | |
518 | 534 | | |
519 | 535 | | |
520 | | - | |
| 536 | + | |
| 537 | + | |
521 | 538 | | |
522 | | - | |
| 539 | + | |
| 540 | + | |
523 | 541 | | |
524 | | - | |
| 542 | + | |
| 543 | + | |
525 | 544 | | |
526 | 545 | | |
527 | 546 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
140 | 140 | | |
141 | 141 | | |
142 | 142 | | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
143 | 161 | | |
144 | 162 | | |
145 | 163 | | |
| |||
252 | 270 | | |
253 | 271 | | |
254 | 272 | | |
255 | | - | |
256 | | - | |
| 273 | + | |
257 | 274 | | |
258 | 275 | | |
259 | 276 | | |
| |||
264 | 281 | | |
265 | 282 | | |
266 | 283 | | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
267 | 393 | | |
268 | 394 | | |
269 | 395 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
86 | | - | |
87 | | - | |
88 | | - | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
89 | 91 | | |
90 | 92 | | |
91 | 93 | | |
| |||
118 | 120 | | |
119 | 121 | | |
120 | 122 | | |
121 | | - | |
122 | | - | |
| 123 | + | |
123 | 124 | | |
124 | 125 | | |
125 | 126 | | |
126 | 127 | | |
127 | 128 | | |
128 | | - | |
129 | | - | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
130 | 133 | | |
131 | 134 | | |
132 | 135 | | |
| |||
Lines changed: 1 addition & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
112 | | - | |
113 | | - | |
| 112 | + | |
114 | 113 | | |
115 | 114 | | |
116 | 115 | | |
| |||
0 commit comments