@ggui-ai/ui-gen 0.28.0 → 0.29.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 (308) hide show
  1. package/dist/{adapter-h4_V69LI.d.ts → adapter-DLQ-5COm.d.ts} +1 -1
  2. package/dist/adapters/base.js +2 -27
  3. package/dist/adapters/base.js.map +1 -1
  4. package/dist/adapters/generation-dispatch.d.ts +14 -6
  5. package/dist/adapters/generation-dispatch.js +40 -19260
  6. package/dist/adapters/generation-dispatch.js.map +1 -1
  7. package/dist/adapters/index.d.ts +1 -1
  8. package/dist/adapters/index.js +25 -3561
  9. package/dist/adapters/index.js.map +1 -1
  10. package/dist/adapters/types.js +2 -9
  11. package/dist/adapters/types.js.map +1 -1
  12. package/dist/advanced/index.d.ts +13 -12
  13. package/dist/advanced/index.js +63 -21954
  14. package/dist/advanced/index.js.map +1 -1
  15. package/dist/{bank-Ctdp3FUA.d.ts → bank-LWaiAtaA.d.ts} +1 -1
  16. package/dist/blueprint-validator.js +6 -2301
  17. package/dist/blueprint-validator.js.map +1 -1
  18. package/dist/boilerplate.d.ts +3 -2
  19. package/dist/boilerplate.js +6 -1867
  20. package/dist/boilerplate.js.map +1 -1
  21. package/dist/check/index.d.ts +3 -2
  22. package/dist/check/index.js +6 -1923
  23. package/dist/check/index.js.map +1 -1
  24. package/dist/chunk-33B3BAWS.js +24 -0
  25. package/dist/chunk-33B3BAWS.js.map +1 -0
  26. package/dist/chunk-3HSGA6NI.js +591 -0
  27. package/dist/chunk-3HSGA6NI.js.map +1 -0
  28. package/dist/chunk-3NNNGNTO.js +1707 -0
  29. package/dist/chunk-3NNNGNTO.js.map +1 -0
  30. package/dist/chunk-3T2HMTON.js +79 -0
  31. package/dist/chunk-3T2HMTON.js.map +1 -0
  32. package/dist/chunk-3ZSSDV3L.js +123 -0
  33. package/dist/chunk-3ZSSDV3L.js.map +1 -0
  34. package/dist/chunk-4MBR5GA3.js +99 -0
  35. package/dist/chunk-4MBR5GA3.js.map +1 -0
  36. package/dist/chunk-56NJFD55.js +337 -0
  37. package/dist/chunk-56NJFD55.js.map +1 -0
  38. package/dist/chunk-5AGTY555.js +26 -0
  39. package/dist/chunk-5AGTY555.js.map +1 -0
  40. package/dist/chunk-5EJM7EGY.js +115 -0
  41. package/dist/chunk-5EJM7EGY.js.map +1 -0
  42. package/dist/chunk-5KXCQLLR.js +529 -0
  43. package/dist/chunk-5KXCQLLR.js.map +1 -0
  44. package/dist/chunk-5VBXHVEH.js +171 -0
  45. package/dist/chunk-5VBXHVEH.js.map +1 -0
  46. package/dist/chunk-6KDDEING.js +515 -0
  47. package/dist/chunk-6KDDEING.js.map +1 -0
  48. package/dist/chunk-6VDRWAP6.js +123 -0
  49. package/dist/chunk-6VDRWAP6.js.map +1 -0
  50. package/dist/chunk-732IBFEJ.js +2400 -0
  51. package/dist/chunk-732IBFEJ.js.map +1 -0
  52. package/dist/chunk-73AURS3I.js +46 -0
  53. package/dist/chunk-73AURS3I.js.map +1 -0
  54. package/dist/chunk-77H5SKLX.js +8 -0
  55. package/dist/chunk-77H5SKLX.js.map +1 -0
  56. package/dist/chunk-7QE3AHLE.js +35 -0
  57. package/dist/chunk-7QE3AHLE.js.map +1 -0
  58. package/dist/chunk-A375NNWN.js +11 -0
  59. package/dist/chunk-A375NNWN.js.map +1 -0
  60. package/dist/chunk-AOU33EFS.js +140 -0
  61. package/dist/chunk-AOU33EFS.js.map +1 -0
  62. package/dist/chunk-BA4QYA6E.js +461 -0
  63. package/dist/chunk-BA4QYA6E.js.map +1 -0
  64. package/dist/chunk-DBP764GL.js +3 -0
  65. package/dist/chunk-DBP764GL.js.map +1 -0
  66. package/dist/chunk-DUU3ZJDQ.js +41 -0
  67. package/dist/chunk-DUU3ZJDQ.js.map +1 -0
  68. package/dist/chunk-DXKRBXNU.js +30 -0
  69. package/dist/chunk-DXKRBXNU.js.map +1 -0
  70. package/dist/chunk-FB7OEEAH.js +1467 -0
  71. package/dist/chunk-FB7OEEAH.js.map +1 -0
  72. package/dist/chunk-FLRNMZV2.js +18 -0
  73. package/dist/chunk-FLRNMZV2.js.map +1 -0
  74. package/dist/chunk-FWJIMKFZ.js +2032 -0
  75. package/dist/chunk-FWJIMKFZ.js.map +1 -0
  76. package/dist/chunk-FXRHWYIQ.js +163 -0
  77. package/dist/chunk-FXRHWYIQ.js.map +1 -0
  78. package/dist/chunk-G3PMV62Z.js +33 -0
  79. package/dist/chunk-G3PMV62Z.js.map +1 -0
  80. package/dist/chunk-GAJI7Y3P.js +13 -0
  81. package/dist/chunk-GAJI7Y3P.js.map +1 -0
  82. package/dist/chunk-GYINWMPR.js +2052 -0
  83. package/dist/chunk-GYINWMPR.js.map +1 -0
  84. package/dist/chunk-HD6ABIK7.js +484 -0
  85. package/dist/chunk-HD6ABIK7.js.map +1 -0
  86. package/dist/chunk-HDQVHYO6.js +100 -0
  87. package/dist/chunk-HDQVHYO6.js.map +1 -0
  88. package/dist/chunk-IHUT3SIW.js +7 -0
  89. package/dist/chunk-IHUT3SIW.js.map +1 -0
  90. package/dist/chunk-JDH5EGNZ.js +126 -0
  91. package/dist/chunk-JDH5EGNZ.js.map +1 -0
  92. package/dist/chunk-JMD4RGSV.js +37 -0
  93. package/dist/chunk-JMD4RGSV.js.map +1 -0
  94. package/dist/chunk-KJWGZL5B.js +33 -0
  95. package/dist/chunk-KJWGZL5B.js.map +1 -0
  96. package/dist/chunk-MKMDQFZ7.js +86 -0
  97. package/dist/chunk-MKMDQFZ7.js.map +1 -0
  98. package/dist/chunk-NF6JUZWF.js +85 -0
  99. package/dist/chunk-NF6JUZWF.js.map +1 -0
  100. package/dist/chunk-O2YC6XDC.js +1933 -0
  101. package/dist/chunk-O2YC6XDC.js.map +1 -0
  102. package/dist/chunk-OVLH5ICV.js +29 -0
  103. package/dist/chunk-OVLH5ICV.js.map +1 -0
  104. package/dist/chunk-PBOYHGSD.js +106 -0
  105. package/dist/chunk-PBOYHGSD.js.map +1 -0
  106. package/dist/chunk-PJFH7QWA.js +81 -0
  107. package/dist/chunk-PJFH7QWA.js.map +1 -0
  108. package/dist/chunk-PUH4CXGZ.js +284 -0
  109. package/dist/chunk-PUH4CXGZ.js.map +1 -0
  110. package/dist/chunk-QLXXPGTV.js +18 -0
  111. package/dist/chunk-QLXXPGTV.js.map +1 -0
  112. package/dist/chunk-R5GIGPW2.js +2845 -0
  113. package/dist/chunk-R5GIGPW2.js.map +1 -0
  114. package/dist/chunk-RH4IUSTO.js +83 -0
  115. package/dist/chunk-RH4IUSTO.js.map +1 -0
  116. package/dist/chunk-S2GVXKKY.js +153 -0
  117. package/dist/chunk-S2GVXKKY.js.map +1 -0
  118. package/dist/chunk-TVHGKFJS.js +58 -0
  119. package/dist/chunk-TVHGKFJS.js.map +1 -0
  120. package/dist/chunk-U7GALWLG.js +66 -0
  121. package/dist/chunk-U7GALWLG.js.map +1 -0
  122. package/dist/chunk-VTC263LT.js +256 -0
  123. package/dist/chunk-VTC263LT.js.map +1 -0
  124. package/dist/chunk-WEOXFEVE.js +739 -0
  125. package/dist/chunk-WEOXFEVE.js.map +1 -0
  126. package/dist/chunk-WYHP46LT.js +28 -0
  127. package/dist/chunk-WYHP46LT.js.map +1 -0
  128. package/dist/chunk-XGLO5LGG.js +274 -0
  129. package/dist/chunk-XGLO5LGG.js.map +1 -0
  130. package/dist/chunk-XRBCRKA2.js +29 -0
  131. package/dist/chunk-XRBCRKA2.js.map +1 -0
  132. package/dist/chunk-XW7ADFFV.js +340 -0
  133. package/dist/chunk-XW7ADFFV.js.map +1 -0
  134. package/dist/chunk-YIQ42IUX.js +34 -0
  135. package/dist/chunk-YIQ42IUX.js.map +1 -0
  136. package/dist/chunk-YJZTUY7B.js +101 -0
  137. package/dist/chunk-YJZTUY7B.js.map +1 -0
  138. package/dist/chunk-Z3CXME3K.js +107 -0
  139. package/dist/chunk-Z3CXME3K.js.map +1 -0
  140. package/dist/classifier/index.js +2 -527
  141. package/dist/classifier/index.js.map +1 -1
  142. package/dist/client-JBPCXU7W.js +4 -0
  143. package/dist/client-JBPCXU7W.js.map +1 -0
  144. package/dist/compose.js +3 -367
  145. package/dist/compose.js.map +1 -1
  146. package/dist/cost-tracker-HHGQ4FTW.js +67 -0
  147. package/dist/cost-tracker-HHGQ4FTW.js.map +1 -0
  148. package/dist/{create-ui-generator-BrZHF0cf.d.ts → create-ui-generator-BY-WeaPi.d.ts} +3 -3
  149. package/dist/{design-mode-DGWN_Gkm.d.ts → design-mode-XyOQmzE0.d.ts} +4 -3
  150. package/dist/{dispatch-B07TI30d.d.ts → dispatch-8LzTddKw.d.ts} +3 -2
  151. package/dist/dist-UALN6ZVB.js +543 -0
  152. package/dist/dist-UALN6ZVB.js.map +1 -0
  153. package/dist/dupe-break-X6K7QFIS.js +4 -0
  154. package/dist/dupe-break-X6K7QFIS.js.map +1 -0
  155. package/dist/evaluation/axis-checks/index.d.ts +5 -4
  156. package/dist/evaluation/axis-checks/index.js +6 -1914
  157. package/dist/evaluation/axis-checks/index.js.map +1 -1
  158. package/dist/evaluation/axis-checks/registry.d.ts +3 -2
  159. package/dist/evaluation/axis-checks/registry.js +3 -1844
  160. package/dist/evaluation/axis-checks/registry.js.map +1 -1
  161. package/dist/evaluation/index.d.ts +49 -132
  162. package/dist/evaluation/index.js +302 -6466
  163. package/dist/evaluation/index.js.map +1 -1
  164. package/dist/evaluation/types.d.ts +3 -2
  165. package/dist/evaluation/types.js +2 -5
  166. package/dist/evaluation/types.js.map +1 -1
  167. package/dist/fragments/index.js +2 -338
  168. package/dist/fragments/index.js.map +1 -1
  169. package/dist/{generate-tSO_shQ0.d.ts → generate-DQ4ci90s.d.ts} +1 -1
  170. package/dist/harness/check/runtime-render/index.d.ts +35 -15
  171. package/dist/harness/check/runtime-render/index.js +6 -2390
  172. package/dist/harness/check/runtime-render/index.js.map +1 -1
  173. package/dist/harness/check/runtime-render/render-check-worker.js +4 -1739
  174. package/dist/harness/check/runtime-render/render-check-worker.js.map +1 -1
  175. package/dist/harness/index.d.ts +3 -2
  176. package/dist/harness/index.js +23 -5126
  177. package/dist/harness/index.js.map +1 -1
  178. package/dist/harness/llm-trace-sink.js +2 -24
  179. package/dist/harness/llm-trace-sink.js.map +1 -1
  180. package/dist/harness/prompts.d.ts +2 -2
  181. package/dist/harness/prompts.js +8 -324
  182. package/dist/harness/prompts.js.map +1 -1
  183. package/dist/harness/result-types.d.ts +6 -5
  184. package/dist/harness/result-types.js +2 -0
  185. package/dist/harness/result-types.js.map +1 -1
  186. package/dist/harness/runtime.d.ts +22 -5
  187. package/dist/harness/runtime.js +10 -2313
  188. package/dist/harness/runtime.js.map +1 -1
  189. package/dist/harness/types-public.d.ts +3 -2
  190. package/dist/harness/types-public.js +16 -2954
  191. package/dist/harness/types-public.js.map +1 -1
  192. package/dist/harness/validator-trace-sink.d.ts +3 -2
  193. package/dist/harness/validator-trace-sink.js +2 -26
  194. package/dist/harness/validator-trace-sink.js.map +1 -1
  195. package/dist/hash.js +2 -39
  196. package/dist/hash.js.map +1 -1
  197. package/dist/hashline-5OKREIRM.js +4 -0
  198. package/dist/hashline-5OKREIRM.js.map +1 -0
  199. package/dist/index.d.ts +50 -11
  200. package/dist/index.js +57 -22015
  201. package/dist/index.js.map +1 -1
  202. package/dist/llm-evaluator-PN3WFCS4.js +653 -0
  203. package/dist/llm-evaluator-PN3WFCS4.js.map +1 -0
  204. package/dist/magic-string.es-2NZTC4GZ.js +1307 -0
  205. package/dist/magic-string.es-2NZTC4GZ.js.map +1 -0
  206. package/dist/patch.d.ts +3 -2
  207. package/dist/patch.js +2 -56
  208. package/dist/patch.js.map +1 -1
  209. package/dist/policy-VCYKGSAC.js +5 -0
  210. package/dist/policy-VCYKGSAC.js.map +1 -0
  211. package/dist/policy.js +2 -35
  212. package/dist/policy.js.map +1 -1
  213. package/dist/primitive-index-2OF6F4TZ.js +131 -0
  214. package/dist/primitive-index-2OF6F4TZ.js.map +1 -0
  215. package/dist/primitive-slice-WTMBLYFJ.js +235 -0
  216. package/dist/primitive-slice-WTMBLYFJ.js.map +1 -0
  217. package/dist/{prompts-BhNUuRoZ.d.ts → prompts-CLZGywMP.d.ts} +1 -1
  218. package/dist/provider-adapter-contract.js +10407 -14204
  219. package/dist/provider-adapter-contract.js.map +1 -1
  220. package/dist/provider-adapter.js +2 -44
  221. package/dist/provider-adapter.js.map +1 -1
  222. package/dist/providers/index.d.ts +89 -1
  223. package/dist/providers/index.js +115 -44
  224. package/dist/providers/index.js.map +1 -1
  225. package/dist/raw-C6KBH5I3.js +141 -0
  226. package/dist/raw-C6KBH5I3.js.map +1 -0
  227. package/dist/raw-FXSBXQTZ.js +7 -0
  228. package/dist/raw-FXSBXQTZ.js.map +1 -0
  229. package/dist/raw-MURDUPGK.js +8 -0
  230. package/dist/raw-MURDUPGK.js.map +1 -0
  231. package/dist/raw-T3GW3UVX.js +8 -0
  232. package/dist/raw-T3GW3UVX.js.map +1 -0
  233. package/dist/render-check-host-ZNIS6BJ5.js +5 -0
  234. package/dist/render-check-host-ZNIS6BJ5.js.map +1 -0
  235. package/dist/sdk-4JNSDNSR.js +6 -0
  236. package/dist/sdk-4JNSDNSR.js.map +1 -0
  237. package/dist/sdk-DIVJMHCX.js +7 -0
  238. package/dist/sdk-DIVJMHCX.js.map +1 -0
  239. package/dist/sdk-QRJOCRTS.js +7 -0
  240. package/dist/sdk-QRJOCRTS.js.map +1 -0
  241. package/dist/tag-balance-CTHCTRJ7.js +123 -0
  242. package/dist/tag-balance-CTHCTRJ7.js.map +1 -0
  243. package/dist/tools/get-primitives-ts.d.ts +1 -1
  244. package/dist/tools/get-primitives-ts.js +3 -1
  245. package/dist/tools/get-primitives-ts.js.map +1 -1
  246. package/dist/tools/render-check-worker.js +3 -40
  247. package/dist/tools/render-check-worker.js.map +1 -1
  248. package/dist/{types-public-h8IMnYuh.d.ts → types-public-hYlrerZh.d.ts} +35 -2
  249. package/dist/validation/index.d.ts +2 -2
  250. package/dist/validation/index.js +3 -498
  251. package/dist/validation/index.js.map +1 -1
  252. package/dist/{visual-evaluator-C2strxqD.d.ts → visual-evaluator-KskajxD5.d.ts} +14 -4
  253. package/dist/visual-evaluator-TGEXYQTP.js +12 -0
  254. package/dist/visual-evaluator-TGEXYQTP.js.map +1 -0
  255. package/dist/workflows.d.ts +3 -2
  256. package/dist/workflows.js +2 -151
  257. package/dist/workflows.js.map +1 -1
  258. package/package.json +20 -16
  259. package/src/adapters/claude/sdk.ts +4 -2
  260. package/src/adapters/claude/tool-bridge.ts +2 -1
  261. package/src/adapters/generation-dispatch.ts +9 -0
  262. package/src/adapters/openai/raw.ts +4 -0
  263. package/src/adapters/openai/sdk.ts +6 -1
  264. package/src/adapters/openai/tokens.ts +21 -7
  265. package/src/adapters/tool-bridge.ts +1 -1
  266. package/src/adapters/tools.ts +1 -1
  267. package/src/advanced/feedback.ts +1 -2
  268. package/src/advanced/generator.ts +4 -3
  269. package/src/boilerplate/free-design-prompt.ts +7 -0
  270. package/src/boilerplate/generate.ts +18 -5
  271. package/src/boilerplate/hard-sections.ts +8 -3
  272. package/src/boilerplate/react-hooks.ts +56 -0
  273. package/src/boilerplate/system-prompt.ts +12 -3
  274. package/src/check/run-tier0.ts +233 -8
  275. package/src/check/type-checker.ts +128 -16
  276. package/src/coding-agent/tools.ts +26 -3
  277. package/src/design-mode.ts +4 -9
  278. package/src/evaluation/axis-checks/checks/state-merge.ts +2 -4
  279. package/src/evaluation/axis-checks/checks/state-payload.ts +1 -28
  280. package/src/evaluation/axis-checks/checks/tint.ts +197 -0
  281. package/src/evaluation/axis-checks/helpers.ts +121 -0
  282. package/src/evaluation/axis-checks/registry.ts +2 -0
  283. package/src/evaluation/criteria/__fixtures__/edge-v2-draw2.json +4629 -0
  284. package/src/evaluation/criteria/bank.ts +1 -1
  285. package/src/evaluation/criteria/edge-instruments.ts +14 -0
  286. package/src/evaluation/criteria/edge-probe-v2.ts +352 -0
  287. package/src/evaluation/criteria/edge-v2.ts +242 -0
  288. package/src/evaluation/criteria/resolve.ts +24 -5
  289. package/src/evaluation/index.ts +3 -5
  290. package/src/evaluation/mcp-server.ts +0 -50
  291. package/src/evaluation/types-public.ts +6 -1
  292. package/src/evaluation/visual-evaluator.ts +161 -30
  293. package/src/harness/check/runtime-render/index.ts +28 -4
  294. package/src/harness/check/runtime-render/render-check.ts +20 -21
  295. package/src/harness/claude-agent-sdk-loader.ts +93 -0
  296. package/src/harness/claude-code-login-query.ts +1 -1
  297. package/src/harness/coding/generate-task-runner.ts +1 -0
  298. package/src/harness/coding/run-coding-turn.ts +3 -0
  299. package/src/harness/coding/run-eval-round.ts +9 -0
  300. package/src/harness/llm-router.ts +50 -2
  301. package/src/harness/runtime.ts +17 -0
  302. package/src/index.ts +9 -0
  303. package/src/providers/anthropic-tool-call.ts +263 -0
  304. package/src/providers/index.ts +13 -0
  305. package/src/tools/get-primitives-ts.ts +1 -1
  306. package/src/tools/render-check.ts +4 -4
  307. package/src/validation/primitives.ts +2 -1
  308. package/src/evaluation/loop.ts +0 -218
@@ -1,46 +1,4 @@
1
- // src/provider-adapter.ts
2
- function makeProviderError(args) {
3
- const out = {
4
- kind: args.kind,
5
- provider: args.provider,
6
- message: args.message,
7
- ...args.status !== void 0 ? { status: args.status } : {},
8
- ...args.retryAfterSec !== void 0 ? { retryAfterSec: args.retryAfterSec } : {}
9
- };
10
- return out;
11
- }
12
- function statusToErrorKind(status) {
13
- if (status === 401) return "unauthorized";
14
- if (status === 403) return "forbidden";
15
- if (status === 429) return "rate-limited";
16
- if (status >= 500 && status < 600) return "server-error";
17
- if (status >= 400 && status < 500) return "client-error";
18
- return "unknown";
19
- }
20
- function defaultValidateConfig(provider, request) {
21
- if (!request.apiKey || request.apiKey.length === 0) {
22
- return {
23
- ok: false,
24
- error: makeProviderError({
25
- kind: "no-credentials",
26
- provider,
27
- message: `${provider}: no API key supplied`
28
- })
29
- };
30
- }
31
- if (!request.route?.model || request.route.model.length === 0) {
32
- return {
33
- ok: false,
34
- error: makeProviderError({
35
- kind: "client-error",
36
- provider,
37
- message: `${provider}: model id is required`
38
- })
39
- };
40
- }
41
- return { ok: true };
42
- }
43
-
44
- export { defaultValidateConfig, makeProviderError, statusToErrorKind };
1
+ export { defaultValidateConfig, makeProviderError, statusToErrorKind } from './chunk-73AURS3I.js';
2
+ import './chunk-G3PMV62Z.js';
45
3
  //# sourceMappingURL=provider-adapter.js.map
46
4
  //# sourceMappingURL=provider-adapter.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/provider-adapter.ts"],"names":[],"mappings":";AA+PO,SAAS,kBAAkB,IAAA,EAMhB;AAChB,EAAA,MAAM,GAAA,GAAqB;AAAA,IACzB,MAAM,IAAA,CAAK,IAAA;AAAA,IACX,UAAU,IAAA,CAAK,QAAA;AAAA,IACf,SAAS,IAAA,CAAK,OAAA;AAAA,IACd,GAAI,KAAK,MAAA,KAAW,MAAA,GAAY,EAAE,MAAA,EAAQ,IAAA,CAAK,MAAA,EAAO,GAAI,EAAC;AAAA,IAC3D,GAAI,KAAK,aAAA,KAAkB,MAAA,GACvB,EAAE,aAAA,EAAe,IAAA,CAAK,aAAA,EAAc,GACpC;AAAC,GACP;AACA,EAAA,OAAO,GAAA;AACT;AAQO,SAAS,kBAAkB,MAAA,EAAmC;AACnE,EAAA,IAAI,MAAA,KAAW,KAAK,OAAO,cAAA;AAC3B,EAAA,IAAI,MAAA,KAAW,KAAK,OAAO,WAAA;AAC3B,EAAA,IAAI,MAAA,KAAW,KAAK,OAAO,cAAA;AAC3B,EAAA,IAAI,MAAA,IAAU,GAAA,IAAO,MAAA,GAAS,GAAA,EAAK,OAAO,cAAA;AAC1C,EAAA,IAAI,MAAA,IAAU,GAAA,IAAO,MAAA,GAAS,GAAA,EAAK,OAAO,cAAA;AAC1C,EAAA,OAAO,SAAA;AACT;AAcO,SAAS,qBAAA,CACd,UACA,OAAA,EACoB;AACpB,EAAA,IAAI,CAAC,OAAA,CAAQ,MAAA,IAAU,OAAA,CAAQ,MAAA,CAAO,WAAW,CAAA,EAAG;AAClD,IAAA,OAAO;AAAA,MACL,EAAA,EAAI,KAAA;AAAA,MACJ,OAAO,iBAAA,CAAkB;AAAA,QACvB,IAAA,EAAM,gBAAA;AAAA,QACN,QAAA;AAAA,QACA,OAAA,EAAS,GAAG,QAAQ,CAAA,qBAAA;AAAA,OACrB;AAAA,KACH;AAAA,EACF;AACA,EAAA,IAAI,CAAC,QAAQ,KAAA,EAAO,KAAA,IAAS,QAAQ,KAAA,CAAM,KAAA,CAAM,WAAW,CAAA,EAAG;AAC7D,IAAA,OAAO;AAAA,MACL,EAAA,EAAI,KAAA;AAAA,MACJ,OAAO,iBAAA,CAAkB;AAAA,QACvB,IAAA,EAAM,cAAA;AAAA,QACN,QAAA;AAAA,QACA,OAAA,EAAS,GAAG,QAAQ,CAAA,sBAAA;AAAA,OACrB;AAAA,KACH;AAAA,EACF;AACA,EAAA,OAAO,EAAE,IAAI,IAAA,EAAK;AACpB","file":"provider-adapter.js","sourcesContent":["/**\n * Provider adapter contract — the narrow surface every concrete LLM\n * provider client (Anthropic, Google, OpenAI, OpenRouter, Bedrock)\n * implements.\n *\n * **Real role:** a provider-agnostic one-shot LLM caller for\n * lightweight callers that need a single `complete()` round-trip — NOT\n * a generation harness. The primary consumer is the negotiator's LLM\n * seam (`@ggui-ai/mcp-server`'s `llm-backed-negotiator.ts`, via\n * {@link selectAdapter} from `./providers/index.js`); other lightweight\n * one-shot callers use it the same way. It is explicitly NOT part of\n * the generation dispatch path: `createUiGenerator()` accepts no\n * adapter option, and generation-call 429 retry/backoff lives entirely\n * in `harness/llm-router.ts`'s `apiCall()` — a separate retry story for\n * a separate call shape (an agentic SDK loop, not a single completion).\n *\n * The contract is deliberately defined independently of concrete\n * adapters so:\n *\n * - Adapter implementations can be written against a stable surface —\n * every concrete adapter MUST pass\n * {@link providerAdapterContract} or it isn't a `ProviderAdapter`.\n * - Downstream one-shot callers build against ONE structured failure\n * shape ({@link ProviderError}) instead of inventing per-provider\n * error UX.\n * - The negotiator + cache layers can branch on\n * `error.kind === 'rate-limited'` etc. without parsing strings.\n *\n * **Scope:**\n *\n * - Defines the interface, the response shape, the error shape,\n * and a contract test runner that asserts every adapter\n * satisfies the seam.\n * - Does NOT call any LLM. The contract is structural; this\n * package's own tests exercise the runner against a deterministic\n * fixture adapter (`provider-adapter-mock.test-util.ts`).\n *\n * **Design choices, locked:**\n *\n * - One discriminated `ProviderError.kind` union, not per-provider\n * subclasses. Every provider's raw error funnels through\n * `mapError` into one of these kinds. Callers branch on `kind`.\n * - Every error carries `provider` + `message`; transport-shaped\n * errors carry `status`; backoff-shaped errors carry\n * `retryAfterSec`. Optional fields don't appear when they don't\n * apply (no `status: undefined` noise in serialized logs).\n * - `validateConfig` is synchronous + does NO I/O. It catches the\n * \"operator never configured the provider\" case (missing key,\n * malformed model id) before we attempt a network call.\n * - `complete` is the single-completion seam. Streaming, tool\n * calling, function calling, and harness retry land in higher\n * layers — adapters stay narrow.\n */\nimport type { LlmProvider, LlmRoute } from '@ggui-ai/protocol';\n\n/**\n * One LLM completion request as the adapter sees it. Plain data so\n * tests can construct it without DI.\n *\n * `route` is a discriminated `LlmRoute` — `(provider, model)` typed\n * together so the model id is structurally constrained to its\n * provider's namespace (per the `MODELS` registry in\n * `@ggui-ai/protocol/types/llm-route`). This makes the #22 / #42 bug\n * class — passing a LiteLLM-prefixed `'anthropic/claude-haiku-4-5'`\n * where Anthropic expected the wire id `'claude-haiku-4-5-20251001'` —\n * a compile error at every adapter call site. The adapter reads the\n * wire-canonical string off `request.route.model` and passes it\n * verbatim to the provider SDK; no transformation step exists to\n * forget.\n */\nexport interface ProviderRequest {\n /** API key. Resolved upstream by `@ggui-ai/cli/byok-resolver`. */\n readonly apiKey: string;\n /**\n * Discriminated `(provider, model)` route. `route.model` is the\n * wire-canonical id the provider's API expects — adapters pass it\n * verbatim with no stripping or remapping.\n */\n readonly route: LlmRoute;\n /** System prompt text. Adapter wires it into the provider's slot. */\n readonly systemPrompt: string;\n /** User prompt text. */\n readonly userPrompt: string;\n /**\n * Optional cap on output tokens. Adapters MUST honor when the\n * provider supports it; when absent, adapters use the provider\n * default.\n */\n readonly maxTokens?: number;\n /**\n * Optional cancellation. Adapters MUST forward into the provider\n * SDK's abort surface and reject with `ProviderError{kind:'aborted'}`\n * when fired.\n */\n readonly signal?: AbortSignal;\n}\n\n/**\n * Successful provider response, normalized.\n *\n * Tool-calling output, multi-turn dialogue, structured-output\n * coercion all land in higher layers — this contract intentionally\n * stays narrow: text + usage + finish reason. The harness layer\n * composes adapters into multi-turn loops.\n */\nexport interface ProviderResponse {\n /** The completion text returned by the provider. */\n readonly text: string;\n /** Token usage, per-call. Required — adapters synthesize 0 if the\n * provider didn't report it (and document that in their adapter). */\n readonly usage: {\n readonly inputTokens: number;\n readonly outputTokens: number;\n };\n /**\n * Why the model stopped. Mapped through a normalized union so\n * callers don't have to know each provider's vocabulary.\n *\n * - `'stop'` model emitted EOS / stop sequence\n * - `'length'` hit `maxTokens` or provider context limit\n * - `'content-filter'` provider safety filter intervened\n * - `'other'` anything else (provider-specific reason)\n */\n readonly finishReason: 'stop' | 'length' | 'content-filter' | 'other';\n}\n\n/**\n * The structured failure contract. Every concrete adapter's\n * `mapError` MUST funnel raw provider errors into this shape so\n * downstream code branches on `kind`, not on string parsing.\n *\n * Discriminator + optional carriers:\n *\n * - `'no-credentials'` — no key supplied (pre-flight failure;\n * usually surfaced by `validateConfig`,\n * not `mapError`).\n * - `'unauthorized'` — provider returned 401. Key invalid /\n * revoked / wrong type.\n * - `'forbidden'` — provider returned 403. Quota exhausted,\n * org-level block, model not allowed for\n * this key. (Distinct from 401 because\n * \"rotate the key\" doesn't help.)\n * - `'rate-limited'` — provider returned 429. Carries\n * `retryAfterSec` when the provider\n * advertised one (`Retry-After` header).\n * - `'server-error'` — provider returned 5xx. Retryable.\n * - `'client-error'` — provider returned other 4xx. Usually\n * non-retryable (bad model id, malformed\n * request).\n * - `'network'` — TCP-level failure, DNS, EAI_AGAIN, etc.\n * No `status`. Retryable.\n * - `'invalid-response'` — provider returned 2xx with a body the\n * adapter couldn't parse. Bug in the\n * adapter or in the provider; treat as\n * non-retryable.\n * - `'aborted'` — caller aborted via `signal`.\n * - `'unknown'` — last-resort bucket. Adapters that hit\n * this should be patched to map the\n * specific case explicitly.\n */\nexport type ProviderErrorKind =\n | 'no-credentials'\n | 'unauthorized'\n | 'forbidden'\n | 'rate-limited'\n | 'server-error'\n | 'client-error'\n | 'network'\n | 'invalid-response'\n | 'aborted'\n | 'unknown';\n\nexport interface ProviderError {\n readonly kind: ProviderErrorKind;\n readonly provider: LlmProvider;\n /** Human-readable message. Safe to log; should not contain key\n * material — adapters MUST scrub before placing here. */\n readonly message: string;\n /** HTTP status when transport-shaped. Absent for pre-flight,\n * network, aborted, invalid-response. */\n readonly status?: number;\n /**\n * Seconds to wait before retrying. Set ONLY for `'rate-limited'`\n * when the provider advertised a `Retry-After` header. Higher-level\n * retry policy uses this when present; falls back to its own\n * exponential backoff when absent.\n */\n readonly retryAfterSec?: number;\n}\n\n/**\n * Pre-flight config validation. Synchronous, no I/O. Catches:\n *\n * - missing or empty API key → no-credentials\n * - missing or empty model id → client-error\n *\n * Adapters MAY widen the check with provider-specific rules\n * (e.g. \"openrouter model id MUST contain a `/`\"). Failures\n * surface through the same {@link ProviderError} so callers branch\n * on one union.\n */\nexport type ProviderValidation =\n | { readonly ok: true }\n | { readonly ok: false; readonly error: ProviderError };\n\n/**\n * The contract every provider client implements.\n */\nexport interface ProviderAdapter {\n /** Provider this adapter speaks to. Stable identifier; lets the\n * caller route a `ProviderRequest` to the right adapter. */\n readonly provider: LlmProvider;\n /**\n * Pre-flight check. MUST return synchronously and MUST NOT touch\n * the network. Returns `{ok: true}` when the request is at least\n * structurally valid; returns `{ok: false, error}` otherwise.\n */\n validateConfig(request: Pick<ProviderRequest, 'apiKey' | 'route'>): ProviderValidation;\n /**\n * Single-completion call. Resolves with `{ok: true, response}` on\n * success or `{ok: false, error}` on any failure (network,\n * provider 4xx/5xx, abort). Implementations MUST:\n *\n * 1. Funnel every raw provider error through `mapError`.\n * 2. NOT throw. The result discriminator IS the error path.\n * 3. Forward `request.signal` into the provider SDK's abort\n * mechanism + return `kind:'aborted'` when fired.\n */\n complete(request: ProviderRequest): Promise<ProviderResult>;\n /**\n * Map an arbitrary thrown / rejected value into a\n * {@link ProviderError}. Exposed (not just internal) so test\n * harnesses + retry policies can normalize errors without going\n * through `complete`.\n *\n * MUST NEVER throw — `mapError(unknown)` is the safety net.\n */\n mapError(raw: unknown): ProviderError;\n}\n\n/**\n * Discriminated result of a `complete` call. Mirrors `validateConfig`\n * so callers never have to handle thrown errors from this seam.\n */\nexport type ProviderResult =\n | { readonly ok: true; readonly response: ProviderResponse }\n | { readonly ok: false; readonly error: ProviderError };\n\n// ─── Helpers concrete adapters compose with ────────────────────────\n\n/**\n * Build a `ProviderError` of the supplied kind. Centralized so\n * concrete adapters don't drift on field shape. Provider-aware so\n * callers don't have to thread it through.\n */\nexport function makeProviderError(args: {\n readonly kind: ProviderErrorKind;\n readonly provider: LlmProvider;\n readonly message: string;\n readonly status?: number;\n readonly retryAfterSec?: number;\n}): ProviderError {\n const out: ProviderError = {\n kind: args.kind,\n provider: args.provider,\n message: args.message,\n ...(args.status !== undefined ? { status: args.status } : {}),\n ...(args.retryAfterSec !== undefined\n ? { retryAfterSec: args.retryAfterSec }\n : {}),\n };\n return out;\n}\n\n/**\n * Map an HTTP status code to the canonical error kind. Adapters\n * call this from `mapError` after they've classified the failure as\n * \"the provider returned a status we understand\". Network / abort /\n * pre-flight live outside this mapping.\n */\nexport function statusToErrorKind(status: number): ProviderErrorKind {\n if (status === 401) return 'unauthorized';\n if (status === 403) return 'forbidden';\n if (status === 429) return 'rate-limited';\n if (status >= 500 && status < 600) return 'server-error';\n if (status >= 400 && status < 500) return 'client-error';\n return 'unknown';\n}\n\n/**\n * Default `validateConfig` implementation. Concrete adapters\n * compose this and add their own provider-specific checks on top.\n *\n * Catches the two universal failures: missing key + missing model.\n * Returns `{ok: true}` when both are present.\n *\n * The model-id check is defense-in-depth — typed `LlmRoute` callers\n * cannot construct a route with an empty model string, but the\n * adapter still validates at runtime in case the request crossed an\n * untyped JSON boundary (e.g. deserialized from a wire format).\n */\nexport function defaultValidateConfig(\n provider: LlmProvider,\n request: Pick<ProviderRequest, 'apiKey' | 'route'>,\n): ProviderValidation {\n if (!request.apiKey || request.apiKey.length === 0) {\n return {\n ok: false,\n error: makeProviderError({\n kind: 'no-credentials',\n provider,\n message: `${provider}: no API key supplied`,\n }),\n };\n }\n if (!request.route?.model || request.route.model.length === 0) {\n return {\n ok: false,\n error: makeProviderError({\n kind: 'client-error',\n provider,\n message: `${provider}: model id is required`,\n }),\n };\n }\n return { ok: true };\n}\n"]}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"provider-adapter.js"}
@@ -140,6 +140,94 @@ interface BedrockAdapterOptions {
140
140
  */
141
141
  declare function createBedrockAdapter(options?: BedrockAdapterOptions): ProviderAdapter;
142
142
 
143
+ /**
144
+ * The one tool the call asks for: the Messages API's own wire shape for a
145
+ * tool (`name`, `description`, `input_schema`), sent as-is under a raw
146
+ * `fetch`. It is not an SDK type and does not stand in for one; this
147
+ * package takes no Anthropic SDK dependency.
148
+ */
149
+ interface AnthropicTool {
150
+ readonly name: string;
151
+ readonly description: string;
152
+ /** The tool's input JSON Schema, sent verbatim. */
153
+ readonly input_schema: Readonly<Record<string, unknown>>;
154
+ }
155
+ interface AnthropicToolCallRequest {
156
+ readonly apiKey: string;
157
+ /** The wire model id, sent verbatim. */
158
+ readonly model: string;
159
+ readonly systemPrompt: string;
160
+ readonly userPrompt: string;
161
+ readonly tool: AnthropicTool;
162
+ /** The answer budget. Absent ⇒ 1024. Headroom is added on top where the model needs it. */
163
+ readonly maxTokens?: number;
164
+ /** Cancels the request. */
165
+ readonly signal?: AbortSignal;
166
+ /** Override for tests and instrumentation. Absent ⇒ the global `fetch` at call time. */
167
+ readonly fetch?: typeof globalThis.fetch;
168
+ /** Override for a proxy endpoint. */
169
+ readonly endpoint?: string;
170
+ }
171
+ /** The tool input, with the response's token usage when it reported one. */
172
+ interface AnthropicToolCallResult {
173
+ readonly input: unknown;
174
+ /**
175
+ * `usage.input_tokens` / `usage.output_tokens` when both are numbers;
176
+ * absent otherwise. An unmetered response reports no usage, never
177
+ * zeros. No `cache_control` is sent, so there are no cache counts.
178
+ */
179
+ readonly usage?: {
180
+ readonly input: number;
181
+ readonly output: number;
182
+ };
183
+ }
184
+ /**
185
+ * How a structured call ended without the tool input it asked for:
186
+ *
187
+ * - `max_tokens`: the budget ran out (`stop_reason: max_tokens`) before
188
+ * the tool call.
189
+ * - `no_tool_call`: the model finished without calling the tool
190
+ * (possible under `auto`).
191
+ * - `refusal`: the model declined (`stop_reason: refusal`).
192
+ * - `http`: the API answered non-2xx.
193
+ * - `malformed`: the body was JSON but not a Messages response.
194
+ */
195
+ declare const ANTHROPIC_STRUCTURED_CALL_FAILURE_KINDS: readonly ["max_tokens", "no_tool_call", "refusal", "http", "malformed"];
196
+ type AnthropicStructuredCallFailureKind = (typeof ANTHROPIC_STRUCTURED_CALL_FAILURE_KINDS)[number];
197
+ /**
198
+ * A structured call that returned no tool input, NAMED by why. The kind
199
+ * is in the message too (`[max_tokens]` …), so a consumer that only
200
+ * surfaces the message (the rerank judge's `reason`) still reports
201
+ * which failure it was.
202
+ */
203
+ declare class AnthropicStructuredCallError extends Error {
204
+ readonly kind: AnthropicStructuredCallFailureKind;
205
+ readonly status: number | undefined;
206
+ readonly stopReason: string | undefined;
207
+ constructor(kind: AnthropicStructuredCallFailureKind, detail: string, extra?: {
208
+ readonly status?: number;
209
+ readonly stopReason?: string;
210
+ });
211
+ }
212
+ /**
213
+ * Whether `err` is an {@link AnthropicStructuredCallError}, by its shape:
214
+ * an `Error` named `AnthropicStructuredCallError` whose `kind` is one of
215
+ * {@link ANTHROPIC_STRUCTURED_CALL_FAILURE_KINDS}.
216
+ *
217
+ * Prefer this to `instanceof`. An `instanceof` check holds only while one
218
+ * copy of this package is installed: a consumer that resolves a second
219
+ * copy (its own `@ggui-ai/ui-gen` at a different version from the one
220
+ * `@ggui-ai/mcp-server` depends on) gets errors from a class it did not
221
+ * import, and every one of them fails the check.
222
+ */
223
+ declare function isAnthropicStructuredCallError(err: unknown): err is AnthropicStructuredCallError;
224
+ /**
225
+ * Send one structured call and return the named tool's input. Every way
226
+ * the turn ends without that input throws an
227
+ * {@link AnthropicStructuredCallError} whose kind says which.
228
+ */
229
+ declare function anthropicToolCall(request: AnthropicToolCallRequest): Promise<AnthropicToolCallResult>;
230
+
143
231
  /**
144
232
  * Public barrel for `@ggui-ai/ui-gen/providers`.
145
233
  *
@@ -204,4 +292,4 @@ declare function createBedrockAdapter(options?: BedrockAdapterOptions): Provider
204
292
  */
205
293
  declare function selectAdapter(provider: LlmProvider): ProviderAdapter;
206
294
 
207
- export { type AnthropicAdapterOptions, type BedrockAdapterOptions, type GoogleAdapterOptions, type OpenAiAdapterOptions, type OpenRouterAdapterOptions, createAnthropicAdapter, createBedrockAdapter, createGoogleAdapter, createOpenAiAdapter, createOpenRouterAdapter, selectAdapter };
295
+ export { ANTHROPIC_STRUCTURED_CALL_FAILURE_KINDS, type AnthropicAdapterOptions, AnthropicStructuredCallError, type AnthropicStructuredCallFailureKind, type AnthropicTool, type AnthropicToolCallRequest, type AnthropicToolCallResult, type BedrockAdapterOptions, type GoogleAdapterOptions, type OpenAiAdapterOptions, type OpenRouterAdapterOptions, anthropicToolCall, createAnthropicAdapter, createBedrockAdapter, createGoogleAdapter, createOpenAiAdapter, createOpenRouterAdapter, isAnthropicStructuredCallError, selectAdapter };
@@ -1,47 +1,7 @@
1
+ import { defaultValidateConfig, makeProviderError, statusToErrorKind } from '../chunk-73AURS3I.js';
2
+ import '../chunk-G3PMV62Z.js';
1
3
  import { AnthropicBedrockMantle, AnthropicBedrock } from '@anthropic-ai/bedrock-sdk';
2
-
3
- // src/provider-adapter.ts
4
- function makeProviderError(args) {
5
- const out = {
6
- kind: args.kind,
7
- provider: args.provider,
8
- message: args.message,
9
- ...args.status !== void 0 ? { status: args.status } : {},
10
- ...args.retryAfterSec !== void 0 ? { retryAfterSec: args.retryAfterSec } : {}
11
- };
12
- return out;
13
- }
14
- function statusToErrorKind(status) {
15
- if (status === 401) return "unauthorized";
16
- if (status === 403) return "forbidden";
17
- if (status === 429) return "rate-limited";
18
- if (status >= 500 && status < 600) return "server-error";
19
- if (status >= 400 && status < 500) return "client-error";
20
- return "unknown";
21
- }
22
- function defaultValidateConfig(provider, request) {
23
- if (!request.apiKey || request.apiKey.length === 0) {
24
- return {
25
- ok: false,
26
- error: makeProviderError({
27
- kind: "no-credentials",
28
- provider,
29
- message: `${provider}: no API key supplied`
30
- })
31
- };
32
- }
33
- if (!request.route?.model || request.route.model.length === 0) {
34
- return {
35
- ok: false,
36
- error: makeProviderError({
37
- kind: "client-error",
38
- provider,
39
- message: `${provider}: model id is required`
40
- })
41
- };
42
- }
43
- return { ok: true };
44
- }
4
+ import { anthropicRejectsForcedToolChoice, isRecord } from '@ggui-ai/protocol';
45
5
 
46
6
  // src/providers/anthropic-wire.ts
47
7
  function parseAnthropicMessagesResponse(raw, provider) {
@@ -704,6 +664,117 @@ function createBedrockAdapter(options = {}) {
704
664
  }
705
665
  };
706
666
  }
667
+ var DEFAULT_ENDPOINT4 = "https://api.anthropic.com/v1/messages";
668
+ var DEFAULT_API_VERSION2 = "2023-06-01";
669
+ var DEFAULT_ANSWER_BUDGET = 1024;
670
+ var ALWAYS_THINKING_HEADROOM_TOKENS = 16e3;
671
+ var ANTHROPIC_STRUCTURED_CALL_FAILURE_KINDS = [
672
+ "max_tokens",
673
+ "no_tool_call",
674
+ "refusal",
675
+ "http",
676
+ "malformed"
677
+ ];
678
+ var AnthropicStructuredCallError = class extends Error {
679
+ kind;
680
+ status;
681
+ stopReason;
682
+ constructor(kind, detail, extra = {}) {
683
+ super(`anthropic structured call [${kind}]: ${detail}`);
684
+ this.name = "AnthropicStructuredCallError";
685
+ this.kind = kind;
686
+ this.status = extra.status;
687
+ this.stopReason = extra.stopReason;
688
+ }
689
+ };
690
+ function isAnthropicStructuredCallError(err) {
691
+ if (!(err instanceof Error) || err.name !== "AnthropicStructuredCallError") {
692
+ return false;
693
+ }
694
+ const kind = Reflect.get(err, "kind");
695
+ return ANTHROPIC_STRUCTURED_CALL_FAILURE_KINDS.some((known) => known === kind);
696
+ }
697
+ async function anthropicToolCall(request) {
698
+ const answerBudget = request.maxTokens ?? DEFAULT_ANSWER_BUDGET;
699
+ const refusesForcedTool = anthropicRejectsForcedToolChoice(request.model);
700
+ const maxTokens = refusesForcedTool ? answerBudget + ALWAYS_THINKING_HEADROOM_TOKENS : answerBudget;
701
+ const toolName = request.tool.name;
702
+ const body = {
703
+ model: request.model,
704
+ max_tokens: maxTokens,
705
+ system: refusesForcedTool ? `${request.systemPrompt}
706
+
707
+ Answer by calling the \`${toolName}\` tool exactly once. Do not answer in text.` : request.systemPrompt,
708
+ messages: [{ role: "user", content: request.userPrompt }],
709
+ tools: [
710
+ {
711
+ name: toolName,
712
+ description: request.tool.description,
713
+ input_schema: request.tool.input_schema
714
+ }
715
+ ],
716
+ tool_choice: refusesForcedTool ? { type: "auto", disable_parallel_tool_use: true } : { type: "tool", name: toolName }
717
+ };
718
+ const fetchImpl = request.fetch ?? globalThis.fetch;
719
+ const response = await fetchImpl(request.endpoint ?? DEFAULT_ENDPOINT4, {
720
+ method: "POST",
721
+ headers: {
722
+ "x-api-key": request.apiKey,
723
+ "anthropic-version": DEFAULT_API_VERSION2,
724
+ "content-type": "application/json"
725
+ },
726
+ body: JSON.stringify(body),
727
+ ...request.signal !== void 0 ? { signal: request.signal } : {}
728
+ });
729
+ if (!response.ok) {
730
+ const text = await response.text();
731
+ throw new AnthropicStructuredCallError(
732
+ "http",
733
+ `HTTP ${response.status}: ${text.slice(0, 500)}`,
734
+ { status: response.status }
735
+ );
736
+ }
737
+ const json = await response.json();
738
+ if (!isRecord(json) || !Array.isArray(json["content"])) {
739
+ throw new AnthropicStructuredCallError(
740
+ "malformed",
741
+ "response body is not a Messages response"
742
+ );
743
+ }
744
+ const stopReason = typeof json["stop_reason"] === "string" ? json["stop_reason"] : void 0;
745
+ const toolUse = json["content"].find(
746
+ (block) => isRecord(block) && block["type"] === "tool_use" && block["name"] === toolName
747
+ );
748
+ if (toolUse !== void 0 && toolUse["input"] !== void 0) {
749
+ const usage = readUsage(json["usage"]);
750
+ return { input: toolUse["input"], ...usage !== void 0 ? { usage } : {} };
751
+ }
752
+ if (stopReason === "max_tokens") {
753
+ throw new AnthropicStructuredCallError(
754
+ "max_tokens",
755
+ `stop_reason=max_tokens before the "${toolName}" tool_use block (max_tokens=${maxTokens})`,
756
+ { stopReason }
757
+ );
758
+ }
759
+ if (stopReason === "refusal") {
760
+ throw new AnthropicStructuredCallError(
761
+ "refusal",
762
+ "the model declined (stop_reason=refusal)",
763
+ { stopReason }
764
+ );
765
+ }
766
+ throw new AnthropicStructuredCallError(
767
+ "no_tool_call",
768
+ `the turn ended (stop_reason=${stopReason ?? "absent"}) without a "${toolName}" tool_use block`,
769
+ stopReason !== void 0 ? { stopReason } : {}
770
+ );
771
+ }
772
+ function readUsage(usage) {
773
+ if (!isRecord(usage)) return void 0;
774
+ const input = usage["input_tokens"];
775
+ const output = usage["output_tokens"];
776
+ return typeof input === "number" && typeof output === "number" ? { input, output } : void 0;
777
+ }
707
778
 
708
779
  // src/providers/index.ts
709
780
  function selectAdapter(provider) {
@@ -721,6 +792,6 @@ function selectAdapter(provider) {
721
792
  }
722
793
  }
723
794
 
724
- export { createAnthropicAdapter, createBedrockAdapter, createGoogleAdapter, createOpenAiAdapter, createOpenRouterAdapter, selectAdapter };
795
+ export { ANTHROPIC_STRUCTURED_CALL_FAILURE_KINDS, AnthropicStructuredCallError, anthropicToolCall, createAnthropicAdapter, createBedrockAdapter, createGoogleAdapter, createOpenAiAdapter, createOpenRouterAdapter, isAnthropicStructuredCallError, selectAdapter };
725
796
  //# sourceMappingURL=index.js.map
726
797
  //# sourceMappingURL=index.js.map