@cartanova/qgrid-cli 2.10.9 → 2.11.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 (318) hide show
  1. package/bundle/dist/_virtual/_rolldown/runtime.js +1 -10
  2. package/bundle/dist/application/monit/log-buffer.js +12 -6
  3. package/bundle/dist/application/monit/monit.frame.js +11 -3
  4. package/bundle/dist/application/monit/monit.types.js +1 -1
  5. package/bundle/dist/application/qgrid/conv-routing.js +9 -6
  6. package/bundle/dist/application/qgrid/expired-token-reminder.js +2 -2
  7. package/bundle/dist/application/qgrid/oauth.js +31 -4
  8. package/bundle/dist/application/qgrid/qgrid-image-generation.js +1 -1
  9. package/bundle/dist/application/qgrid/qgrid-response-format.js +22 -20
  10. package/bundle/dist/application/qgrid/qgrid-run-lifecycle.js +43 -34
  11. package/bundle/dist/application/qgrid/qgrid.dispatcher.js +128 -93
  12. package/bundle/dist/application/qgrid/qgrid.frame.js +930 -49
  13. package/bundle/dist/application/qgrid/qgrid.types.js +212 -5
  14. package/bundle/dist/application/qgrid/schema-prompt.js +75 -48
  15. package/bundle/dist/application/qgrid/slack-user-map.js +1 -1
  16. package/bundle/dist/application/qgrid/token-death.js +1 -1
  17. package/bundle/dist/application/qgrid/token-subscriber.js +83 -30
  18. package/bundle/dist/application/qgrid/token-trigger-setup.js +1 -1
  19. package/bundle/dist/application/qgrid/token-window-keepalive.js +8 -6
  20. package/bundle/dist/application/qgrid/tool-emulation-schema.js +13 -13
  21. package/bundle/dist/application/qgrid/tool-emulation.js +19 -15
  22. package/bundle/dist/application/request-log/json-schema-type-text.js +29 -12
  23. package/bundle/dist/application/request-log/request-log.model.js +83 -69
  24. package/bundle/dist/application/request-log/request-log.types.js +8 -2
  25. package/bundle/dist/application/request-log/zod-code-format.js +1 -1
  26. package/bundle/dist/application/request-log-step/request-log-step.model.js +1 -1
  27. package/bundle/dist/application/request-log-step/request-log-step.types.js +1 -1
  28. package/bundle/dist/application/setting/setting.constant.js +1 -1
  29. package/bundle/dist/application/setting/setting.model.js +2 -2
  30. package/bundle/dist/application/setting/setting.store.js +2 -2
  31. package/bundle/dist/application/setting/setting.types.js +1 -1
  32. package/bundle/dist/application/sonamu.generated.js +40 -16
  33. package/bundle/dist/application/sonamu.generated.sso.js +2 -1
  34. package/bundle/dist/application/token/token.model.js +26 -9
  35. package/bundle/dist/application/token/token.types.js +20 -3
  36. package/bundle/dist/i18n/en.js +15 -1
  37. package/bundle/dist/i18n/ko.js +15 -1
  38. package/bundle/dist/i18n/sd.generated.js +2 -1
  39. package/bundle/dist/migrations/20260807133553_manual__backfill_request_log_cost.js +8 -6
  40. package/bundle/dist/migrations/20261018215031_alter_request_logs_add1_alter1.js +15 -0
  41. package/bundle/dist/server-bootstrap.js +4 -2
  42. package/bundle/dist/server-error-handler.js +1 -1
  43. package/bundle/dist/sonamu.config.js +37 -8
  44. package/bundle/dist/startup-migrations.js +17 -7
  45. package/bundle/dist/testing/global.js +1 -1
  46. package/bundle/dist/testing/schema-bench.js +0 -0
  47. package/bundle/dist/testing/test-database-name.js +1 -1
  48. package/bundle/dist/utils/providers/anthropic/anthropic-constants.js +1 -1
  49. package/bundle/dist/utils/providers/anthropic/anthropic-dispatcher.js +11 -5
  50. package/bundle/dist/utils/providers/anthropic/anthropic-quota.js +4 -4
  51. package/bundle/dist/utils/providers/anthropic/anthropic-thinking.js +1 -1
  52. package/bundle/dist/utils/providers/anthropic/claude-session.js +20 -19
  53. package/bundle/dist/utils/providers/anthropic/fence-strip.js +1 -1
  54. package/bundle/dist/utils/providers/anthropic/stream-json-adapter.js +49 -23
  55. package/bundle/dist/utils/providers/common/credentials.js +5 -1
  56. package/bundle/dist/utils/providers/common/effort.js +3 -3
  57. package/bundle/dist/utils/providers/common/model-cost.js +69 -14
  58. package/bundle/dist/utils/providers/common/provider-types.js +29 -1
  59. package/bundle/dist/utils/providers/common/schema-validation.js +78 -40
  60. package/bundle/dist/utils/providers/common/smooth-weighted-round-robin.js +1 -1
  61. package/bundle/dist/utils/providers/common/strictifier.js +62 -43
  62. package/bundle/dist/utils/providers/common/thinking.js +3 -2
  63. package/bundle/dist/utils/providers/common/ttft.js +1 -1
  64. package/bundle/dist/utils/providers/grok/grok-backend-protocol.js +427 -0
  65. package/bundle/dist/utils/providers/grok/grok-constants.js +55 -0
  66. package/bundle/dist/utils/providers/grok/grok-direct-client.js +196 -0
  67. package/bundle/dist/utils/providers/grok/grok-dispatcher.js +1313 -0
  68. package/bundle/dist/utils/providers/grok/grok-headers.js +118 -0
  69. package/bundle/dist/utils/providers/grok/grok-media-client.js +420 -0
  70. package/bundle/dist/utils/providers/grok/grok-models.js +114 -0
  71. package/bundle/dist/utils/providers/grok/grok-oauth.js +455 -0
  72. package/bundle/dist/utils/providers/grok/grok-quota.js +119 -0
  73. package/bundle/dist/utils/providers/grok/grok-refresh.js +192 -0
  74. package/bundle/dist/utils/providers/grok/grok-types.js +186 -0
  75. package/bundle/dist/utils/providers/grok/grok-voice-client.js +199 -0
  76. package/bundle/dist/utils/providers/grok/index.js +11 -0
  77. package/bundle/dist/utils/providers/openai/openai-backend-protocol.js +111 -83
  78. package/bundle/dist/utils/providers/openai/openai-callback-relay.js +3 -2
  79. package/bundle/dist/utils/providers/openai/openai-constants.js +1 -1
  80. package/bundle/dist/utils/providers/openai/openai-direct-client.js +23 -7
  81. package/bundle/dist/utils/providers/openai/openai-dispatcher.js +143 -106
  82. package/bundle/dist/utils/providers/openai/openai-image-generation.js +48 -33
  83. package/bundle/dist/utils/providers/openai/openai-oauth.js +28 -13
  84. package/bundle/dist/utils/providers/openai/openai-quota.js +38 -27
  85. package/bundle/dist/utils/providers/openai/openai-refresh.js +17 -9
  86. package/bundle/dist/utils/providers/openai/openai-sse.js +1 -1
  87. package/bundle/dist/utils/providers/openai/openai-transport-config.js +1 -1
  88. package/bundle/dist/utils/quiet-hours.js +1 -1
  89. package/bundle/dist/utils/slack-notify.js +14 -8
  90. package/bundle/dist/utils/subset-loaders.js +4 -5
  91. package/bundle/src/application/monit/log-buffer.ts +23 -9
  92. package/bundle/src/application/monit/monit.frame.ts +22 -5
  93. package/bundle/src/application/monit/monit.types.ts +6 -0
  94. package/bundle/src/application/qgrid/conv-routing.test.ts +76 -4
  95. package/bundle/src/application/qgrid/conv-routing.ts +35 -9
  96. package/bundle/src/application/qgrid/expired-token-reminder.ts +9 -1
  97. package/bundle/src/application/qgrid/oauth.ts +51 -15
  98. package/bundle/src/application/qgrid/qgrid-image-generation.ts +9 -0
  99. package/bundle/src/application/qgrid/qgrid-response-format.ts +50 -25
  100. package/bundle/src/application/qgrid/qgrid-run-lifecycle.test.ts +33 -0
  101. package/bundle/src/application/qgrid/qgrid-run-lifecycle.ts +87 -40
  102. package/bundle/src/application/qgrid/qgrid.dispatcher.test.ts +97 -0
  103. package/bundle/src/application/qgrid/qgrid.dispatcher.ts +274 -126
  104. package/bundle/src/application/qgrid/qgrid.frame.test.ts +1013 -3
  105. package/bundle/src/application/qgrid/qgrid.frame.ts +1415 -60
  106. package/bundle/src/application/qgrid/qgrid.types.ts +335 -0
  107. package/bundle/src/application/qgrid/schema-prompt.ts +105 -41
  108. package/bundle/src/application/qgrid/slack-user-map.ts +5 -0
  109. package/bundle/src/application/qgrid/token-death.ts +4 -0
  110. package/bundle/src/application/qgrid/token-subscriber.test.ts +21 -19
  111. package/bundle/src/application/qgrid/token-subscriber.ts +186 -53
  112. package/bundle/src/application/qgrid/token-trigger-setup.ts +2 -0
  113. package/bundle/src/application/qgrid/token-window-keepalive.ts +49 -6
  114. package/bundle/src/application/qgrid/tool-emulation-schema.ts +33 -29
  115. package/bundle/src/application/qgrid/tool-emulation.ts +52 -27
  116. package/bundle/src/application/request-log/json-schema-type-text.test.ts +5 -5
  117. package/bundle/src/application/request-log/json-schema-type-text.ts +81 -26
  118. package/bundle/src/application/request-log/request-log.entity.json +8 -0
  119. package/bundle/src/application/request-log/request-log.model.test.ts +111 -4
  120. package/bundle/src/application/request-log/request-log.model.ts +279 -145
  121. package/bundle/src/application/request-log/request-log.types.ts +17 -0
  122. package/bundle/src/application/request-log/zod-code-format.ts +11 -0
  123. package/bundle/src/application/request-log-step/request-log-step.model.ts +1 -0
  124. package/bundle/src/application/request-log-step/request-log-step.types.ts +2 -0
  125. package/bundle/src/application/setting/setting.constant.ts +9 -0
  126. package/bundle/src/application/setting/setting.model.ts +12 -2
  127. package/bundle/src/application/setting/setting.store.ts +5 -1
  128. package/bundle/src/application/setting/setting.types.ts +8 -0
  129. package/bundle/src/application/sonamu.generated.http +135 -0
  130. package/bundle/src/application/sonamu.generated.sso.ts +3 -0
  131. package/bundle/src/application/sonamu.generated.ts +29 -0
  132. package/bundle/src/application/token/token.identity.test.ts +20 -0
  133. package/bundle/src/application/token/token.model.ts +66 -7
  134. package/bundle/src/application/token/token.types.ts +24 -1
  135. package/bundle/src/i18n/en.ts +19 -0
  136. package/bundle/src/i18n/ko.ts +21 -0
  137. package/bundle/src/i18n/sd.generated.ts +24 -2
  138. package/bundle/src/migrations/20260807133553_manual__backfill_request_log_cost.ts +16 -8
  139. package/bundle/src/migrations/20261018215031_alter_request_logs_add1_alter1.ts +15 -0
  140. package/bundle/src/server-bootstrap.ts +4 -2
  141. package/bundle/src/server-error-handler.ts +1 -0
  142. package/bundle/src/sonamu.config.ts +69 -7
  143. package/bundle/src/startup-migrations.ts +27 -9
  144. package/bundle/src/testing/global.ts +20 -0
  145. package/bundle/src/testing/schema-bench.ts +105 -30
  146. package/bundle/src/testing/test-database-name.ts +2 -0
  147. package/bundle/src/utils/providers/anthropic/anthropic-constants.ts +8 -0
  148. package/bundle/src/utils/providers/anthropic/anthropic-dispatcher.ts +41 -6
  149. package/bundle/src/utils/providers/anthropic/anthropic-quota.ts +7 -3
  150. package/bundle/src/utils/providers/anthropic/anthropic-thinking.ts +6 -0
  151. package/bundle/src/utils/providers/anthropic/claude-session.ts +58 -24
  152. package/bundle/src/utils/providers/anthropic/fence-strip.ts +11 -0
  153. package/bundle/src/utils/providers/anthropic/stream-json-adapter.ts +110 -45
  154. package/bundle/src/utils/providers/common/credentials.ts +8 -0
  155. package/bundle/src/utils/providers/common/effort.ts +9 -2
  156. package/bundle/src/utils/providers/common/model-cost.test.ts +48 -1
  157. package/bundle/src/utils/providers/common/model-cost.ts +259 -158
  158. package/bundle/src/utils/providers/common/provider-dispatcher.ts +98 -2
  159. package/bundle/src/utils/providers/common/provider-types.ts +46 -3
  160. package/bundle/src/utils/providers/common/schema-validation.test.ts +5 -1
  161. package/bundle/src/utils/providers/common/schema-validation.ts +124 -56
  162. package/bundle/src/utils/providers/common/smooth-weighted-round-robin.ts +4 -0
  163. package/bundle/src/utils/providers/common/strictifier.ts +185 -59
  164. package/bundle/src/utils/providers/common/thinking.ts +2 -2
  165. package/bundle/src/utils/providers/common/ttft.ts +4 -2
  166. package/bundle/src/utils/providers/grok/__fixtures__/golden-responses-1.0.60.json +164 -0
  167. package/bundle/src/utils/providers/grok/grok-backend-protocol.test.ts +325 -0
  168. package/bundle/src/utils/providers/grok/grok-backend-protocol.ts +721 -0
  169. package/bundle/src/utils/providers/grok/grok-constants.ts +105 -0
  170. package/bundle/src/utils/providers/grok/grok-direct-client.test.ts +179 -0
  171. package/bundle/src/utils/providers/grok/grok-direct-client.ts +313 -0
  172. package/bundle/src/utils/providers/grok/grok-dispatcher.test.ts +1395 -0
  173. package/bundle/src/utils/providers/grok/grok-dispatcher.ts +2105 -0
  174. package/bundle/src/utils/providers/grok/grok-headers.test.ts +149 -0
  175. package/bundle/src/utils/providers/grok/grok-headers.ts +199 -0
  176. package/bundle/src/utils/providers/grok/grok-media-client.test.ts +446 -0
  177. package/bundle/src/utils/providers/grok/grok-media-client.ts +703 -0
  178. package/bundle/src/utils/providers/grok/grok-models.test.ts +96 -0
  179. package/bundle/src/utils/providers/grok/grok-models.ts +161 -0
  180. package/bundle/src/utils/providers/grok/grok-oauth.test.ts +406 -0
  181. package/bundle/src/utils/providers/grok/grok-oauth.ts +771 -0
  182. package/bundle/src/utils/providers/grok/grok-quota.test.ts +142 -0
  183. package/bundle/src/utils/providers/grok/grok-quota.ts +198 -0
  184. package/bundle/src/utils/providers/grok/grok-refresh.test.ts +239 -0
  185. package/bundle/src/utils/providers/grok/grok-refresh.ts +325 -0
  186. package/bundle/src/utils/providers/grok/grok-types.test.ts +252 -0
  187. package/bundle/src/utils/providers/grok/grok-types.ts +374 -0
  188. package/bundle/src/utils/providers/grok/grok-voice-client.test.ts +321 -0
  189. package/bundle/src/utils/providers/grok/grok-voice-client.ts +284 -0
  190. package/bundle/src/utils/providers/grok/index.ts +20 -0
  191. package/bundle/src/utils/providers/openai/openai-backend-protocol.ts +221 -137
  192. package/bundle/src/utils/providers/openai/openai-callback-relay.ts +12 -1
  193. package/bundle/src/utils/providers/openai/openai-constants.ts +2 -0
  194. package/bundle/src/utils/providers/openai/openai-direct-client.ts +111 -21
  195. package/bundle/src/utils/providers/openai/openai-dispatcher.ts +322 -169
  196. package/bundle/src/utils/providers/openai/openai-image-generation.ts +116 -36
  197. package/bundle/src/utils/providers/openai/openai-oauth.ts +48 -20
  198. package/bundle/src/utils/providers/openai/openai-quota.ts +77 -46
  199. package/bundle/src/utils/providers/openai/openai-refresh.ts +42 -18
  200. package/bundle/src/utils/providers/openai/openai-sse.ts +27 -3
  201. package/bundle/src/utils/providers/openai/openai-transport-config.ts +2 -0
  202. package/bundle/src/utils/quiet-hours.ts +12 -1
  203. package/bundle/src/utils/slack-notify.ts +44 -13
  204. package/bundle/src/utils/subset-loaders.ts +7 -7
  205. package/bundle/web-dist/client/assets/clsx-5XM_pHvN.js +1 -0
  206. package/bundle/web-dist/client/assets/index-BA7uQ-6c.js +31 -0
  207. package/bundle/web-dist/client/assets/index-Be2qCZmI.css +1 -0
  208. package/bundle/web-dist/client/assets/logs-C47OJGEI.js +1 -0
  209. package/bundle/web-dist/client/assets/monit-BS9no0dU.js +4 -0
  210. package/bundle/web-dist/client/assets/plus-sdACTfH0.js +1 -0
  211. package/bundle/web-dist/client/assets/refresh-cw-CY8o_1cT.js +1 -0
  212. package/bundle/web-dist/client/assets/request-model-BRtFuZvj.js +1 -0
  213. package/bundle/web-dist/client/assets/routes-kqgkUxE8.js +5 -0
  214. package/bundle/web-dist/client/assets/{services.generated-BsieU37H.js → services.generated-CefiDXEv.js} +5 -5
  215. package/bundle/web-dist/client/assets/settings-DNDvFGSw.js +1 -0
  216. package/bundle/web-dist/client/assets/show-u8Np69q3.js +2 -0
  217. package/bundle/web-dist/client/assets/tokens-QvP410NW.js +1 -0
  218. package/bundle/web-dist/client/assets/total-cost-MnfKU8IN.js +1 -0
  219. package/bundle/web-dist/client/assets/use-oauth-login-flow-Bzdh28Ws.js +1 -0
  220. package/bundle/web-dist/client/assets/use-update-token-mutation-CfJKaxmR.js +1 -0
  221. package/bundle/web-dist/client/assets/vendor-react-CUFFrVN9.js +244 -0
  222. package/bundle/web-dist/client/assets/vendor-tanstack-Bf_jag9G.js +1 -0
  223. package/bundle/web-dist/client/index.html +6 -6
  224. package/bundle/web-dist/server/assets/clsx-D_N5PN_2.js +16 -0
  225. package/bundle/web-dist/server/assets/{lazyRouteComponent-Dtd0NR4r.js → lazyRouteComponent-D8iTIHyn.js} +129 -2
  226. package/bundle/web-dist/server/assets/logs-B3OTd9hy.js +825 -0
  227. package/bundle/web-dist/server/assets/{monit-DvzribSE.js → monit-B2hqorPe.js} +385 -126
  228. package/bundle/web-dist/server/assets/plus-DwG7h9kq.js +28 -0
  229. package/bundle/web-dist/server/assets/{react-dom-B4a6-uuR.js → react-dom-BIYQzBqG.js} +2 -129
  230. package/bundle/web-dist/server/assets/refresh-cw-mMBkwOq0.js +44 -0
  231. package/bundle/web-dist/server/assets/{request-model-CbqfnQOJ.js → request-model-I6OdODSH.js} +15 -6
  232. package/bundle/web-dist/server/assets/{routes-BAPWTizT.js → routes-B95YlUv2.js} +760 -213
  233. package/bundle/web-dist/server/assets/{services.generated-CEbGjsI0.js → services.generated-DQATJ6qf.js} +12821 -12194
  234. package/bundle/web-dist/server/assets/settings-C3gbGk0m.js +830 -0
  235. package/bundle/web-dist/server/assets/{show-CxVZTAdv.js → show-Bxaj3rhH.js} +1355 -419
  236. package/bundle/web-dist/server/assets/tokens-CZjH3cB7.js +1038 -0
  237. package/bundle/web-dist/server/assets/total-cost-fTE9Xy82.js +18 -0
  238. package/bundle/web-dist/server/assets/use-oauth-login-flow-CKDHgc3U.js +2379 -0
  239. package/bundle/web-dist/server/assets/{use-update-token-mutation-CfYmk_4_.js → use-update-token-mutation-BEbgOzaa.js} +1 -1
  240. package/bundle/web-dist/server/entry-server.generated.js +4303 -22810
  241. package/dist/cli.js +9 -9
  242. package/package.json +4 -11
  243. package/postinstall.mjs +12 -0
  244. package/skills/qgrid/SKILL.md +1 -0
  245. package/skills/qgrid/references/cli-env-and-server-boot.md +4 -1
  246. package/skills/qgrid/references/decision-rationale.md +24 -1
  247. package/skills/qgrid/references/grok-runtime.md +89 -0
  248. package/skills/qgrid/references/provider-runtime-differences.md +30 -29
  249. package/skills/qgrid/references/repo-map.md +10 -0
  250. package/skills/qgrid/references/request-log-run-lifecycle.md +1 -1
  251. package/skills/qgrid/references/sonamu-api-web-flow.md +1 -1
  252. package/skills/qgrid/references/token-auth-quota-lifecycle.md +56 -3
  253. package/bundle/dist/node_modules/.pnpm/@jridgewell_sourcemap-codec@1.5.5/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.js +0 -406
  254. package/bundle/dist/node_modules/.pnpm/@vitest_expect@4.1.10/node_modules/@vitest/expect/dist/index.js +0 -1507
  255. package/bundle/dist/node_modules/.pnpm/@vitest_pretty-format@4.1.10/node_modules/@vitest/pretty-format/dist/index.js +0 -887
  256. package/bundle/dist/node_modules/.pnpm/@vitest_runner@4.1.10/node_modules/@vitest/runner/dist/chunk-artifact.js +0 -2756
  257. package/bundle/dist/node_modules/.pnpm/@vitest_runner@4.1.10/node_modules/@vitest/runner/dist/index.js +0 -8
  258. package/bundle/dist/node_modules/.pnpm/@vitest_runner@4.1.10/node_modules/@vitest/runner/dist/utils.js +0 -8
  259. package/bundle/dist/node_modules/.pnpm/@vitest_snapshot@4.1.10/node_modules/@vitest/snapshot/dist/index.js +0 -922
  260. package/bundle/dist/node_modules/.pnpm/@vitest_spy@4.1.10/node_modules/@vitest/spy/dist/index.js +0 -386
  261. package/bundle/dist/node_modules/.pnpm/@vitest_utils@4.1.10/node_modules/@vitest/utils/dist/chunk-pathe.M-eThtNZ.js +0 -121
  262. package/bundle/dist/node_modules/.pnpm/@vitest_utils@4.1.10/node_modules/@vitest/utils/dist/constants.js +0 -51
  263. package/bundle/dist/node_modules/.pnpm/@vitest_utils@4.1.10/node_modules/@vitest/utils/dist/diff.js +0 -1317
  264. package/bundle/dist/node_modules/.pnpm/@vitest_utils@4.1.10/node_modules/@vitest/utils/dist/display.js +0 -561
  265. package/bundle/dist/node_modules/.pnpm/@vitest_utils@4.1.10/node_modules/@vitest/utils/dist/error.js +0 -40
  266. package/bundle/dist/node_modules/.pnpm/@vitest_utils@4.1.10/node_modules/@vitest/utils/dist/helpers.js +0 -272
  267. package/bundle/dist/node_modules/.pnpm/@vitest_utils@4.1.10/node_modules/@vitest/utils/dist/offset.js +0 -27
  268. package/bundle/dist/node_modules/.pnpm/@vitest_utils@4.1.10/node_modules/@vitest/utils/dist/serialize.js +0 -77
  269. package/bundle/dist/node_modules/.pnpm/@vitest_utils@4.1.10/node_modules/@vitest/utils/dist/source-map.js +0 -381
  270. package/bundle/dist/node_modules/.pnpm/@vitest_utils@4.1.10/node_modules/@vitest/utils/dist/timers.js +0 -51
  271. package/bundle/dist/node_modules/.pnpm/chai@6.2.2/node_modules/chai/index.js +0 -2986
  272. package/bundle/dist/node_modules/.pnpm/expect-type@1.3.0/node_modules/expect-type/dist/branding.js +0 -10
  273. package/bundle/dist/node_modules/.pnpm/expect-type@1.3.0/node_modules/expect-type/dist/index.js +0 -109
  274. package/bundle/dist/node_modules/.pnpm/expect-type@1.3.0/node_modules/expect-type/dist/messages.js +0 -10
  275. package/bundle/dist/node_modules/.pnpm/expect-type@1.3.0/node_modules/expect-type/dist/overloads.js +0 -10
  276. package/bundle/dist/node_modules/.pnpm/expect-type@1.3.0/node_modules/expect-type/dist/utils.js +0 -10
  277. package/bundle/dist/node_modules/.pnpm/magic-string@0.30.21/node_modules/magic-string/dist/magic-string.es.js +0 -1126
  278. package/bundle/dist/node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/index.js +0 -21
  279. package/bundle/dist/node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.js +0 -432
  280. package/bundle/dist/node_modules/.pnpm/tinybench@2.9.0/node_modules/tinybench/dist/index.js +0 -517
  281. package/bundle/dist/node_modules/.pnpm/tinyrainbow@3.1.0/node_modules/tinyrainbow/dist/index.js +0 -101
  282. package/bundle/dist/node_modules/.pnpm/vite@8.0.3_@emnapi_core@1.11.2_@emnapi_runtime@1.11.2_@types_node@25.0.7_esbuild@0.27.4_5b35fc1fb85d2af4d105e0d74f940f50/node_modules/vite/dist/node/module-runner.js +0 -1265
  283. package/bundle/dist/node_modules/.pnpm/vitest@4.1.10_@opentelemetry_api@1.9.0_@types_node@25.0.7_@vitest_coverage-v8@4.1.10_vi_a1977b93af7bb69308bcb1dbab39b618/node_modules/vitest/dist/chunks/_commonjsHelpers.D26ty3Ew.js +0 -9
  284. package/bundle/dist/node_modules/.pnpm/vitest@4.1.10_@opentelemetry_api@1.9.0_@types_node@25.0.7_@vitest_coverage-v8@4.1.10_vi_a1977b93af7bb69308bcb1dbab39b618/node_modules/vitest/dist/chunks/benchmark.CX_oY03V.js +0 -41
  285. package/bundle/dist/node_modules/.pnpm/vitest@4.1.10_@opentelemetry_api@1.9.0_@types_node@25.0.7_@vitest_coverage-v8@4.1.10_vi_a1977b93af7bb69308bcb1dbab39b618/node_modules/vitest/dist/chunks/evaluatedModules.Dg1zASAC.js +0 -19
  286. package/bundle/dist/node_modules/.pnpm/vitest@4.1.10_@opentelemetry_api@1.9.0_@types_node@25.0.7_@vitest_coverage-v8@4.1.10_vi_a1977b93af7bb69308bcb1dbab39b618/node_modules/vitest/dist/chunks/index.Chj8NDwU.js +0 -202
  287. package/bundle/dist/node_modules/.pnpm/vitest@4.1.10_@opentelemetry_api@1.9.0_@types_node@25.0.7_@vitest_coverage-v8@4.1.10_vi_a1977b93af7bb69308bcb1dbab39b618/node_modules/vitest/dist/chunks/index.DdgEv5B1.js +0 -46
  288. package/bundle/dist/node_modules/.pnpm/vitest@4.1.10_@opentelemetry_api@1.9.0_@types_node@25.0.7_@vitest_coverage-v8@4.1.10_vi_a1977b93af7bb69308bcb1dbab39b618/node_modules/vitest/dist/chunks/rpc.MzXet3jl.js +0 -119
  289. package/bundle/dist/node_modules/.pnpm/vitest@4.1.10_@opentelemetry_api@1.9.0_@types_node@25.0.7_@vitest_coverage-v8@4.1.10_vi_a1977b93af7bb69308bcb1dbab39b618/node_modules/vitest/dist/chunks/test.DNmyFkvJ.js +0 -3044
  290. package/bundle/dist/node_modules/.pnpm/vitest@4.1.10_@opentelemetry_api@1.9.0_@types_node@25.0.7_@vitest_coverage-v8@4.1.10_vi_a1977b93af7bb69308bcb1dbab39b618/node_modules/vitest/dist/chunks/utils.BX5Fg8C4.js +0 -59
  291. package/bundle/dist/node_modules/.pnpm/vitest@4.1.10_@opentelemetry_api@1.9.0_@types_node@25.0.7_@vitest_coverage-v8@4.1.10_vi_a1977b93af7bb69308bcb1dbab39b618/node_modules/vitest/dist/index.js +0 -28
  292. package/bundle/dist/testing/setup-mocks.js +0 -16
  293. package/bundle/src/testing/setup-mocks.ts +0 -44
  294. package/bundle/web-dist/client/assets/index-Bw2s88Ot.css +0 -1
  295. package/bundle/web-dist/client/assets/index-CrXKu_J8.js +0 -106
  296. package/bundle/web-dist/client/assets/logs-B2SmWJXA.js +0 -1
  297. package/bundle/web-dist/client/assets/monit-D-JwXXoA.js +0 -1
  298. package/bundle/web-dist/client/assets/plus-B62CuqT8.js +0 -1
  299. package/bundle/web-dist/client/assets/refresh-cw-NNcU0Cmq.js +0 -1
  300. package/bundle/web-dist/client/assets/request-model-CojtinqK.js +0 -1
  301. package/bundle/web-dist/client/assets/routes-C5r4gTvY.js +0 -5
  302. package/bundle/web-dist/client/assets/settings-D3tDSAck.js +0 -1
  303. package/bundle/web-dist/client/assets/show-Cah_kUKC.js +0 -2
  304. package/bundle/web-dist/client/assets/tokens-DU2Iyxxd.js +0 -1
  305. package/bundle/web-dist/client/assets/use-oauth-login-flow-D0UaR9_e.js +0 -1
  306. package/bundle/web-dist/client/assets/use-update-token-mutation-DAq0F8p-.js +0 -1
  307. package/bundle/web-dist/client/assets/vendor-react-DH4kUfK2.js +0 -9
  308. package/bundle/web-dist/client/assets/vendor-tanstack-DJRQAbrY.js +0 -1
  309. package/bundle/web-dist/server/assets/logs-l91avYif.js +0 -509
  310. package/bundle/web-dist/server/assets/plus-KZrECewT.js +0 -19
  311. package/bundle/web-dist/server/assets/refresh-cw-BND93JrF.js +0 -23
  312. package/bundle/web-dist/server/assets/settings-BZR5HSAL.js +0 -461
  313. package/bundle/web-dist/server/assets/tokens-D1hb4eKk.js +0 -448
  314. package/bundle/web-dist/server/assets/use-oauth-login-flow-Cvdy0zF8.js +0 -178
  315. package/dist/cli.d.ts +0 -10
  316. /package/bundle/web-dist/client/assets/{cost-DH2jZbrw.js → cost-DB3HbU7T.js} +0 -0
  317. /package/bundle/web-dist/client/assets/{preload-helper-ca-nBW7U.js → preload-helper-DWTEM3RW.js} +0 -0
  318. /package/bundle/web-dist/server/assets/{cost-eEHeTRT5.js → cost-BC9yzyA9.js} +0 -0
@@ -10,6 +10,7 @@
10
10
  * @see https://platform.claude.com/docs/en/about-claude/pricing
11
11
  */
12
12
 
13
+ import { GROK_USD_PER_TICK } from "../grok/grok-constants";
13
14
  import { type OpenAIEffort } from "./effort";
14
15
 
15
16
  export interface ModelCosts {
@@ -52,105 +53,107 @@ const LONG_CONTEXT_272K: NonNullable<ModelCosts["longContext"]> = {
52
53
  // 미기재 모델은 xhigh 까지만 받는다.
53
54
  type OpenAIModelSpec = ModelCosts & { maxEffort?: OpenAIEffort };
54
55
 
55
- const OPENAI_COSTS: Record<string, OpenAIModelSpec> = {
56
- // GPT-6 Astra: Standard API-equivalent pricing, verified 2026-09-07.
57
- // Codex subscription catalog supports ultra; the public API lists only through max.
58
- // @see https://developers.openai.com/api/docs/models/gpt-6-astra
59
- // @see https://developers.openai.com/api/docs/pricing
60
- "gpt-6-astra": {
61
- maxEffort: "ultra",
62
- inputTokens: 10,
63
- outputTokens: 50,
64
- cachedInputTokens: 1,
65
- cacheCreationInputTokens: 12.5,
66
- longContext: LONG_CONTEXT_272K,
67
- },
68
- // GPT-6.1 Sol (2026-09-29 DevDay 출시): Standard API pricing verified 2026-09-30. GPT-6 Sol 과 같고 cached input 만 절반.
69
- // Codex 카탈로그(2026-09-30)는 ultra 까지 허용하고 기본 effort 는 low 다(GPT-6 Sol 은 medium).
70
- // qgrid 의 요청 형태 + codex_cli_rs/0.147.0 헤더로 2026-09-30 구독 경로 라이브 생성 성공.
71
- // @see https://developers.openai.com/api/docs/models/gpt-6.1-sol
72
- "gpt-6.1-sol": {
73
- maxEffort: "ultra",
74
- inputTokens: 2,
75
- outputTokens: 10,
76
- cachedInputTokens: 0.1,
77
- cacheCreationInputTokens: 2.5,
78
- longContext: LONG_CONTEXT_272K,
79
- },
80
- // GPT-6 Sol, Luna (2026-09-22 출시): Standard API pricing verified 2026-09-23. GPT-5.6 Sol/Luna 의 절반 단가.
81
- // Codex 카탈로그(2026-09-23)는 Sol 에 ultra, Luna 에 max 까지 허용하고 기본 effort 는 둘 다 medium 이다.
82
- // @see https://developers.openai.com/api/docs/models/gpt-6-sol
83
- // @see https://developers.openai.com/api/docs/models/gpt-6-luna
84
- "gpt-6-sol": {
85
- maxEffort: "ultra",
86
- inputTokens: 2,
87
- outputTokens: 10,
88
- cachedInputTokens: 0.2,
89
- cacheCreationInputTokens: 2.5,
90
- longContext: LONG_CONTEXT_272K,
91
- },
92
- "gpt-6-luna": {
93
- maxEffort: "max",
94
- inputTokens: 0.1,
95
- outputTokens: 0.5,
96
- cachedInputTokens: 0.01,
97
- cacheCreationInputTokens: 0.125,
98
- longContext: LONG_CONTEXT_272K,
99
- },
100
- // GPT-5.6 Sol, Terra, Luna. cache write 단가는 외부 logger/manual usage 입력을 위해
101
- // 유지한다. 현재 OpenAI 응답 usage 에 cache write 토큰 필드가 없으면 비용은 0으로 계산된다.
102
- // @see https://developers.openai.com/api/docs/models/gpt-5.6-sol
103
- // @see https://developers.openai.com/api/docs/models/gpt-5.6-terra
104
- // @see https://developers.openai.com/api/docs/models/gpt-5.6-luna
105
- // Sol promotional rates are available at least through 2026-11-21.
106
- // No confirmed end date/replacement rate: recheck official pricing instead of auto-reverting.
107
- "gpt-5.6-sol": {
108
- maxEffort: "ultra",
109
- inputTokens: 4,
110
- outputTokens: 20,
111
- cachedInputTokens: 0.4,
112
- cacheCreationInputTokens: 5,
113
- longContext: LONG_CONTEXT_272K,
114
- },
115
- "gpt-5.6-terra": {
116
- maxEffort: "ultra",
117
- inputTokens: 2,
118
- outputTokens: 12,
119
- cachedInputTokens: 0.2,
120
- cacheCreationInputTokens: 2.5,
121
- longContext: LONG_CONTEXT_272K,
122
- },
123
- "gpt-5.6-luna": {
124
- maxEffort: "max",
125
- inputTokens: 0.2,
126
- outputTokens: 1.2,
127
- cachedInputTokens: 0.02,
128
- cacheCreationInputTokens: 0.25,
129
- longContext: LONG_CONTEXT_272K,
130
- },
131
- // https://openai.com/index/introducing-gpt-5-5/ (2026-04 출시)
132
- "gpt-5.5": {
133
- inputTokens: 5,
134
- outputTokens: 30,
135
- cachedInputTokens: 0.5,
136
- longContext: LONG_CONTEXT_272K,
137
- },
138
- // 아래 gpt-5.4 / gpt-5.4-mini / gpt-5.3-codex / gpt-5.2 는 qgrid 가 쓰는 ChatGPT 구독 Codex 경로에서
139
- // 더 이상 제공되지 않는다(5.4 계열은 2026-08-31 retired, 대체 gpt-5.6-terra / gpt-5.6-luna).
140
- // 과거 request log 재산정(cost_source 없는 legacy 행)에 필요하므로 단가 행은 유지한다.
141
- // https://openai.com/index/introducing-gpt-5-4/ (2026-03 출시)
142
- "gpt-5.4": {
143
- inputTokens: 2.5,
144
- outputTokens: 15,
145
- cachedInputTokens: 0.25,
146
- longContext: LONG_CONTEXT_272K,
147
- },
148
- "gpt-5.4-mini": { inputTokens: 0.75, outputTokens: 4.5, cachedInputTokens: 0.075 },
149
- // gpt-5.2와 동일 단가 (cached = input의 10%)
150
- "gpt-5.3-codex": { inputTokens: 1.75, outputTokens: 14, cachedInputTokens: 0.175 },
151
- // https://openai.com/index/introducing-gpt-5-2/ (cached input 90% 할인 명시)
152
- "gpt-5.2": { inputTokens: 1.75, outputTokens: 14, cachedInputTokens: 0.175 },
153
- };
56
+ const OPENAI_COSTS = new Map<string, OpenAIModelSpec>(
57
+ Object.entries({
58
+ // GPT-6 Astra: Standard API-equivalent pricing, verified 2026-09-07.
59
+ // Codex subscription catalog supports ultra; the public API lists only through max.
60
+ // @see https://developers.openai.com/api/docs/models/gpt-6-astra
61
+ // @see https://developers.openai.com/api/docs/pricing
62
+ "gpt-6-astra": {
63
+ maxEffort: "ultra",
64
+ inputTokens: 10,
65
+ outputTokens: 50,
66
+ cachedInputTokens: 1,
67
+ cacheCreationInputTokens: 12.5,
68
+ longContext: LONG_CONTEXT_272K,
69
+ },
70
+ // GPT-6.1 Sol (2026-09-29 DevDay 출시): Standard API pricing verified 2026-09-30. GPT-6 Sol 과 같고 cached input 만 절반.
71
+ // Codex 카탈로그(2026-09-30)는 ultra 까지 허용하고 기본 effort 는 low 다(GPT-6 Sol 은 medium).
72
+ // qgrid 의 요청 형태 + codex_cli_rs/0.147.0 헤더로 2026-09-30 구독 경로 라이브 생성 성공.
73
+ // @see https://developers.openai.com/api/docs/models/gpt-6.1-sol
74
+ "gpt-6.1-sol": {
75
+ maxEffort: "ultra",
76
+ inputTokens: 2,
77
+ outputTokens: 10,
78
+ cachedInputTokens: 0.1,
79
+ cacheCreationInputTokens: 2.5,
80
+ longContext: LONG_CONTEXT_272K,
81
+ },
82
+ // GPT-6 Sol, Luna (2026-09-22 출시): Standard API pricing verified 2026-09-23. GPT-5.6 Sol/Luna 의 절반 단가.
83
+ // Codex 카탈로그(2026-09-23)는 Sol 에 ultra, Luna 에 max 까지 허용하고 기본 effort 는 둘 다 medium 이다.
84
+ // @see https://developers.openai.com/api/docs/models/gpt-6-sol
85
+ // @see https://developers.openai.com/api/docs/models/gpt-6-luna
86
+ "gpt-6-sol": {
87
+ maxEffort: "ultra",
88
+ inputTokens: 2,
89
+ outputTokens: 10,
90
+ cachedInputTokens: 0.2,
91
+ cacheCreationInputTokens: 2.5,
92
+ longContext: LONG_CONTEXT_272K,
93
+ },
94
+ "gpt-6-luna": {
95
+ maxEffort: "max",
96
+ inputTokens: 0.1,
97
+ outputTokens: 0.5,
98
+ cachedInputTokens: 0.01,
99
+ cacheCreationInputTokens: 0.125,
100
+ longContext: LONG_CONTEXT_272K,
101
+ },
102
+ // GPT-5.6 Sol, Terra, Luna. cache write 단가는 외부 logger/manual usage 입력을 위해
103
+ // 유지한다. 현재 OpenAI 응답 usage 에 cache write 토큰 필드가 없으면 비용은 0으로 계산된다.
104
+ // @see https://developers.openai.com/api/docs/models/gpt-5.6-sol
105
+ // @see https://developers.openai.com/api/docs/models/gpt-5.6-terra
106
+ // @see https://developers.openai.com/api/docs/models/gpt-5.6-luna
107
+ // Sol promotional rates are available at least through 2026-11-21.
108
+ // No confirmed end date/replacement rate: recheck official pricing instead of auto-reverting.
109
+ "gpt-5.6-sol": {
110
+ maxEffort: "ultra",
111
+ inputTokens: 4,
112
+ outputTokens: 20,
113
+ cachedInputTokens: 0.4,
114
+ cacheCreationInputTokens: 5,
115
+ longContext: LONG_CONTEXT_272K,
116
+ },
117
+ "gpt-5.6-terra": {
118
+ maxEffort: "ultra",
119
+ inputTokens: 2,
120
+ outputTokens: 12,
121
+ cachedInputTokens: 0.2,
122
+ cacheCreationInputTokens: 2.5,
123
+ longContext: LONG_CONTEXT_272K,
124
+ },
125
+ "gpt-5.6-luna": {
126
+ maxEffort: "max",
127
+ inputTokens: 0.2,
128
+ outputTokens: 1.2,
129
+ cachedInputTokens: 0.02,
130
+ cacheCreationInputTokens: 0.25,
131
+ longContext: LONG_CONTEXT_272K,
132
+ },
133
+ // https://openai.com/index/introducing-gpt-5-5/ (2026-04 출시)
134
+ "gpt-5.5": {
135
+ inputTokens: 5,
136
+ outputTokens: 30,
137
+ cachedInputTokens: 0.5,
138
+ longContext: LONG_CONTEXT_272K,
139
+ },
140
+ // 아래 gpt-5.4 / gpt-5.4-mini / gpt-5.3-codex / gpt-5.2 는 qgrid 가 쓰는 ChatGPT 구독 Codex 경로에서
141
+ // 더 이상 제공되지 않는다(5.4 계열은 2026-08-31 retired, 대체 gpt-5.6-terra / gpt-5.6-luna).
142
+ // 과거 request log 재산정(cost_source 없는 legacy 행)에 필요하므로 단가 행은 유지한다.
143
+ // https://openai.com/index/introducing-gpt-5-4/ (2026-03 출시)
144
+ "gpt-5.4": {
145
+ inputTokens: 2.5,
146
+ outputTokens: 15,
147
+ cachedInputTokens: 0.25,
148
+ longContext: LONG_CONTEXT_272K,
149
+ },
150
+ "gpt-5.4-mini": { inputTokens: 0.75, outputTokens: 4.5, cachedInputTokens: 0.075 },
151
+ // gpt-5.2와 동일 단가 (cached = input의 10%)
152
+ "gpt-5.3-codex": { inputTokens: 1.75, outputTokens: 14, cachedInputTokens: 0.175 },
153
+ // https://openai.com/index/introducing-gpt-5-2/ (cached input 90% 할인 명시)
154
+ "gpt-5.2": { inputTokens: 1.75, outputTokens: 14, cachedInputTokens: 0.175 },
155
+ }),
156
+ );
154
157
 
155
158
  // ── Anthropic ───────────────────────────────────────────────────────
156
159
 
@@ -159,7 +162,7 @@ function anthropicCosts(
159
162
  outputTokens: number,
160
163
  overrides: Pick<Partial<ModelCosts>, "cachedInputTokens" | "longContext"> = {},
161
164
  ): ModelCosts {
162
- return {
165
+ const costs: ModelCosts = {
163
166
  inputTokens,
164
167
  outputTokens,
165
168
  // 표준 cache read 는 base input 의 0.1x. Fable 5.1 처럼 공식 특례 단가가 있으면 override 한다.
@@ -169,86 +172,172 @@ function anthropicCosts(
169
172
  cacheCreationInputTokens: inputTokens * 2,
170
173
  cacheCreationInputTokens5m: inputTokens * 1.25,
171
174
  cacheCreationInputTokens1h: inputTokens * 2,
172
- // Haiku 5.5 처럼 프롬프트 길이 티어가 있는 모델만 long-context 배율을 가진다.
173
- ...(overrides.longContext ? { longContext: overrides.longContext } : {}),
174
175
  };
176
+
177
+ // Haiku 5.5 처럼 프롬프트 길이 티어가 있는 모델만 long-context 배율을 가진다.
178
+ if (overrides.longContext) costs.longContext = overrides.longContext;
179
+
180
+ return costs;
175
181
  }
176
182
 
177
183
  // 가격 출처: https://platform.claude.com/docs/en/about-claude/pricing (2026-10-08 확인. 2026-10-07 에 Sonnet 5.5
178
184
  // cache read 가 $0.20→$0.10(0.05x)으로 인하됐고, 그 외 기존 모델 단가는 변동 없음)
179
- const ANTHROPIC_COSTS: Record<string, ModelCosts> = {
180
- // Fable 5.1 (2026-09-01 출시): input/output 은 Fable 5 와 같고 cache read 만 0.025x($0.25) 특례.
181
- // @see https://platform.claude.com/docs/en/models/fable-5-1/overview
182
- "claude-fable-5-1": anthropicCosts(10, 50, { cachedInputTokens: 0.25 }),
183
- "claude-fable-5": anthropicCosts(10, 50),
184
- sonnet: anthropicCosts(3, 15),
185
- "claude-3-5-haiku": anthropicCosts(0.8, 4),
186
- "claude-haiku-4-5": anthropicCosts(1, 5),
187
- "claude-3-5-sonnet": anthropicCosts(3, 15),
188
- "claude-3-7-sonnet": anthropicCosts(3, 15),
189
- "claude-sonnet-4": anthropicCosts(3, 15),
190
- "claude-sonnet-4-5": anthropicCosts(3, 15),
191
- "claude-sonnet-4-6": anthropicCosts(3, 15),
192
- "claude-sonnet-4-7": anthropicCosts(3, 15),
193
- "claude-opus-4": anthropicCosts(15, 75),
194
- "claude-opus-4-1": anthropicCosts(15, 75),
195
- "claude-opus-4-5": anthropicCosts(5, 25),
196
- "claude-opus-4-6": anthropicCosts(5, 25),
197
- "claude-opus-4-7": anthropicCosts(5, 25),
198
- "claude-opus-4-8": anthropicCosts(5, 25),
199
- "claude-opus-5": anthropicCosts(5, 25),
200
- // Opus 5.5 (2026-09-22 출시): $4/$20. cache read 는 0.05x($0.20) 특례, cache write 는 표준 배율($5/$8).
201
- // @see https://platform.claude.com/docs/en/models/opus-5-5/overview
202
- "claude-opus-5-5": anthropicCosts(4, 20, { cachedInputTokens: 0.2 }),
203
- // Sonnet 5 의 introductory $2/$10 이 정식 단가로 확정됐다. 2026-09-01 에 예정됐던 $3/$15 인상은
204
- // 취소됐으므로 날짜 분기 없이 고정 단가로 계산한다.
205
- "claude-sonnet-5": anthropicCosts(2, 10),
206
- // Sonnet 5.5 (2026-09-28 출시): Sonnet 5 와 같은 $2/$10. cache read 는 출시 시 표준 0.1x($0.20)였다가
207
- // 2026-10-07 Haiku 5.5 출시와 함께 Opus 5.5 와 같은 0.05x($0.10)로 인하됐다(API 릴리스 노트). 비용은 요청 시점
208
- // 단가로 기록되므로 날짜 분기 없이 현행 단가만 둔다. cache write 는 표준 배율($2.50/$4).
209
- // @see https://platform.claude.com/docs/en/release-notes/overview (2026-10-07)
210
- "claude-sonnet-5-5": anthropicCosts(2, 10, { cachedInputTokens: 0.1 }),
211
- // Haiku 5.5 (2026-10-07 출시): 프롬프트 길이 티어 단가. 100K 이하 $0.10/$0.50, cache read 0.1x($0.01),
212
- // cache write 5m $0.125 / 1h $0.20. 입력이 100K 를 넘으면 input/cache read/cache write/output 모두 5x
213
- // ($0.50/$0.05/$0.625·$1/$2.50)가 요청 전체에 적용된다. 1M 컨텍스트 모델 중 유일하게 길이별 단가를 쓴다.
214
- // @see https://platform.claude.com/docs/en/models/haiku-5-5/overview
215
- "claude-haiku-5-5": anthropicCosts(0.1, 0.5, {
216
- longContext: {
217
- threshold: 100_000,
218
- inputMultiplier: 5,
219
- cachedInputMultiplier: 5,
220
- outputMultiplier: 5,
221
- },
185
+ const ANTHROPIC_COSTS = new Map<string, ModelCosts>(
186
+ Object.entries({
187
+ // Fable 5.1 (2026-09-01 출시): input/output 은 Fable 5 와 같고 cache read 만 0.025x($0.25) 특례.
188
+ // @see https://platform.claude.com/docs/en/models/fable-5-1/overview
189
+ "claude-fable-5-1": anthropicCosts(10, 50, { cachedInputTokens: 0.25 }),
190
+ "claude-fable-5": anthropicCosts(10, 50),
191
+ sonnet: anthropicCosts(3, 15),
192
+ "claude-3-5-haiku": anthropicCosts(0.8, 4),
193
+ "claude-haiku-4-5": anthropicCosts(1, 5),
194
+ "claude-3-5-sonnet": anthropicCosts(3, 15),
195
+ "claude-3-7-sonnet": anthropicCosts(3, 15),
196
+ "claude-sonnet-4": anthropicCosts(3, 15),
197
+ "claude-sonnet-4-5": anthropicCosts(3, 15),
198
+ "claude-sonnet-4-6": anthropicCosts(3, 15),
199
+ "claude-sonnet-4-7": anthropicCosts(3, 15),
200
+ "claude-opus-4": anthropicCosts(15, 75),
201
+ "claude-opus-4-1": anthropicCosts(15, 75),
202
+ "claude-opus-4-5": anthropicCosts(5, 25),
203
+ "claude-opus-4-6": anthropicCosts(5, 25),
204
+ "claude-opus-4-7": anthropicCosts(5, 25),
205
+ "claude-opus-4-8": anthropicCosts(5, 25),
206
+ "claude-opus-5": anthropicCosts(5, 25),
207
+ // Opus 5.5 (2026-09-22 출시): $4/$20. cache read 는 0.05x($0.20) 특례, cache write 는 표준 배율($5/$8).
208
+ // @see https://platform.claude.com/docs/en/models/opus-5-5/overview
209
+ "claude-opus-5-5": anthropicCosts(4, 20, { cachedInputTokens: 0.2 }),
210
+ // Sonnet 5 의 introductory $2/$10 이 정식 단가로 확정됐다. 2026-09-01 에 예정됐던 $3/$15 인상은
211
+ // 취소됐으므로 날짜 분기 없이 고정 단가로 계산한다.
212
+ "claude-sonnet-5": anthropicCosts(2, 10),
213
+ // Sonnet 5.5 (2026-09-28 출시): Sonnet 5 와 같은 $2/$10. cache read 는 출시 시 표준 0.1x($0.20)였다가
214
+ // 2026-10-07 Haiku 5.5 출시와 함께 Opus 5.5 와 같은 0.05x($0.10)로 인하됐다(API 릴리스 노트). 비용은 요청 시점
215
+ // 단가로 기록되므로 날짜 분기 없이 현행 단가만 둔다. cache write 는 표준 배율($2.50/$4).
216
+ // @see https://platform.claude.com/docs/en/release-notes/overview (2026-10-07)
217
+ "claude-sonnet-5-5": anthropicCosts(2, 10, { cachedInputTokens: 0.1 }),
218
+ // Haiku 5.5 (2026-10-07 출시): 프롬프트 길이 티어 단가. 100K 이하 $0.10/$0.50, cache read 0.1x($0.01),
219
+ // cache write 5m $0.125 / 1h $0.20. 입력이 100K 를 넘으면 input/cache read/cache write/output 모두 5x
220
+ // ($0.50/$0.05/$0.625·$1/$2.50)가 요청 전체에 적용된다. 1M 컨텍스트 모델 중 유일하게 길이별 단가를 쓴다.
221
+ // @see https://platform.claude.com/docs/en/models/haiku-5-5/overview
222
+ "claude-haiku-5-5": anthropicCosts(0.1, 0.5, {
223
+ longContext: {
224
+ threshold: 100_000,
225
+ inputMultiplier: 5,
226
+ cachedInputMultiplier: 5,
227
+ outputMultiplier: 5,
228
+ },
229
+ }),
222
230
  }),
223
- };
231
+ );
224
232
 
225
233
  // gpt-5.3-codex-spark 는 research preview 로 공식 token 단가가 아직 final 이 아니다.
226
234
  // 지원 타입은 유지하되, 공식 단가가 공개될 때까지 아래 generic estimate 로 계산한다.
227
235
  // @see https://help.openai.com/en/articles/20001106-codex-rate-card
228
236
  const DEFAULT_COSTS: ModelCosts = { inputTokens: 3, outputTokens: 15, cachedInputTokens: 0.3 };
229
237
 
238
+ // -- Grok (xAI) --
239
+ //
240
+ // Fallback only. Grok chat, image and video responses report `usage.cost_in_usd_ticks`, which is
241
+ // authoritative (costSource "provider"); these rows price a response that omitted it.
242
+ // Source: api.x.ai/v1/language-models and /image-generation-models read with the subscription JWT
243
+ // in the 2026-10-16 live probe. One tick is 1e-10 USD (grok-4.7 lists 20000/5000/60000 ticks per
244
+ // input/cached/output token against the public $2/$0.50/$6 per million).
245
+ const GROK_TICKS_PER_USD = Math.round(1 / GROK_USD_PER_TICK);
246
+
247
+ /** USD for a provider-reported `cost_in_usd_ticks` amount. */
248
+ export function usdFromGrokTicks(ticks: number): number {
249
+ return ticks / GROK_TICKS_PER_USD;
250
+ }
251
+
252
+ function grokTokenCosts(input: number, cached: number, output: number): ModelCosts {
253
+ // ticks per token -> USD per 1M tokens.
254
+ const perMillion = (ticks: number) => (ticks * 1_000_000) / GROK_TICKS_PER_USD;
255
+
256
+ return {
257
+ inputTokens: perMillion(input),
258
+ cachedInputTokens: perMillion(cached),
259
+ outputTokens: perMillion(output),
260
+ };
261
+ }
262
+
263
+ const GROK_COSTS = new Map<string, ModelCosts>(
264
+ Object.entries({
265
+ "grok-4.7": grokTokenCosts(20_000, 5_000, 60_000),
266
+ "grok-4.6": grokTokenCosts(20_000, 5_000, 60_000),
267
+ "grok-4.5": grokTokenCosts(20_000, 5_000, 60_000),
268
+ }),
269
+ );
270
+
271
+ // Ticks per generated image at the default 1k resolution (the probe's quality 1k image cost exactly
272
+ // this amount). Unlisted image models have no estimate.
273
+ const GROK_IMAGE_PRICE_TICKS = new Map<string, number>(
274
+ Object.entries({
275
+ "grok-imagine-image-quality": 500_000_000,
276
+ }),
277
+ );
278
+
279
+ export interface GrokMediaCost {
280
+ costUsd: number;
281
+ costSource: "provider" | "pricing_table";
282
+ /** Ticks reported by xAI, or the catalog-price estimate in ticks. */
283
+ ticks: number;
284
+ }
285
+
286
+ /**
287
+ * Image cost: the reported ticks when present, otherwise the per-image catalog price times the
288
+ * image count. Undefined when neither is known, so callers store an unknown cost, not a guess.
289
+ */
290
+ export function grokImageCost(
291
+ model: string,
292
+ imageCount: number,
293
+ reportedTicks?: number,
294
+ ): GrokMediaCost | undefined {
295
+ if (reportedTicks !== undefined) return grokReportedCost(reportedTicks);
296
+ const perImage = GROK_IMAGE_PRICE_TICKS.get(model.split("/").pop() ?? model);
297
+
298
+ if (perImage === undefined) return undefined;
299
+ const ticks = perImage * imageCount;
300
+
301
+ return { costUsd: usdFromGrokTicks(ticks), costSource: "pricing_table", ticks };
302
+ }
303
+
304
+ /** Video/voice cost: only a provider-reported amount; there is no catalog estimate. */
305
+ export function grokReportedCost(reportedTicks: number | undefined): GrokMediaCost | undefined {
306
+ return reportedTicks === undefined
307
+ ? undefined
308
+ : { costUsd: usdFromGrokTicks(reportedTicks), costSource: "provider", ticks: reportedTicks };
309
+ }
310
+
230
311
  /** Codex 백엔드가 이 모델에 허용하는 최대 effort. 카탈로그에 없는 모델은 xhigh 까지다. */
231
312
  export function openaiModelMaxEffort(model: string): OpenAIEffort {
232
- return OPENAI_COSTS[model]?.maxEffort ?? "xhigh";
313
+ return OPENAI_COSTS.get(model)?.maxEffort ?? "xhigh";
233
314
  }
234
315
 
235
316
  export function getModelCosts(model: string): ModelCosts {
236
317
  const normalizedModel = (model.split("/").pop() ?? model).replace(/\[1m\]$/i, "");
237
- return OPENAI_COSTS[normalizedModel] ?? ANTHROPIC_COSTS[normalizedModel] ?? DEFAULT_COSTS;
318
+
319
+ return (
320
+ OPENAI_COSTS.get(normalizedModel) ??
321
+ ANTHROPIC_COSTS.get(normalizedModel) ??
322
+ GROK_COSTS.get(normalizedModel) ??
323
+ DEFAULT_COSTS
324
+ );
238
325
  }
239
326
 
240
327
  // Verified Fast API rates for the currently served Codex models (2026-10-16).
241
328
  // Applies to all token categories and long context; not the 2.5x subscription quota multiplier.
242
329
  // https://developers.openai.com/api/docs/pricing
243
- const OPENAI_FAST_MULTIPLIERS: Record<string, number> = {
244
- "gpt-6-astra": 2,
245
- "gpt-6.1-sol": 2,
246
- "gpt-6-sol": 2,
247
- "gpt-6-luna": 2,
248
- "gpt-5.6-sol": 2,
249
- "gpt-5.6-terra": 2,
250
- "gpt-5.6-luna": 2,
251
- };
330
+ const OPENAI_FAST_MULTIPLIERS = new Map<string, number>(
331
+ Object.entries({
332
+ "gpt-6-astra": 2,
333
+ "gpt-6.1-sol": 2,
334
+ "gpt-6-sol": 2,
335
+ "gpt-6-luna": 2,
336
+ "gpt-5.6-sol": 2,
337
+ "gpt-5.6-terra": 2,
338
+ "gpt-5.6-luna": 2,
339
+ }),
340
+ );
252
341
 
253
342
  export function calculateCostUsd(
254
343
  model: string,
@@ -266,17 +355,22 @@ export function calculateCostUsd(
266
355
  const cachedInput = usage.cachedInputTokens ?? 0;
267
356
  const cacheCreationInput5m = Math.max(usage.cacheCreationInputTokens5m ?? 0, 0);
268
357
  const cacheCreationInput1h = Math.max(usage.cacheCreationInputTokens1h ?? 0, 0);
358
+
269
359
  const cacheCreationInput = Math.max(
270
360
  usage.cacheCreationInputTokens ?? 0,
271
361
  cacheCreationInput5m + cacheCreationInput1h,
272
362
  );
363
+
273
364
  const classifiedCacheCreationInput5m = Math.min(cacheCreationInput5m, cacheCreationInput);
365
+
274
366
  const classifiedCacheCreationInput1h = Math.min(
275
367
  cacheCreationInput1h,
276
368
  cacheCreationInput - classifiedCacheCreationInput5m,
277
369
  );
370
+
278
371
  const unclassifiedCacheCreationInput =
279
372
  cacheCreationInput - classifiedCacheCreationInput5m - classifiedCacheCreationInput1h;
373
+
280
374
  const nonCachedInput = Math.max(usage.inputTokens - cachedInput - cacheCreationInput, 0);
281
375
 
282
376
  // long-context 할증: 전체 입력(input_tokens, cache 포함)이 threshold 초과 시 요청 전체에 배율 적용
@@ -284,15 +378,19 @@ export function calculateCostUsd(
284
378
  const isLongContext = lc !== undefined && usage.inputTokens > lc.threshold;
285
379
  const inputRate = costs.inputTokens * (isLongContext ? lc.inputMultiplier : 1);
286
380
  const cachedRate = costs.cachedInputTokens * (isLongContext ? lc.cachedInputMultiplier : 1);
381
+
287
382
  const cacheCreationFallbackRate =
288
383
  (costs.cacheCreationInputTokens ?? costs.inputTokens) *
289
384
  (isLongContext ? lc.inputMultiplier : 1);
385
+
290
386
  const cacheCreation5mRate =
291
387
  (costs.cacheCreationInputTokens5m ?? costs.cacheCreationInputTokens ?? costs.inputTokens) *
292
388
  (isLongContext ? lc.inputMultiplier : 1);
389
+
293
390
  const cacheCreation1hRate =
294
391
  (costs.cacheCreationInputTokens1h ?? costs.cacheCreationInputTokens ?? costs.inputTokens) *
295
392
  (isLongContext ? lc.inputMultiplier : 1);
393
+
296
394
  const outputRate = costs.outputTokens * (isLongContext ? lc.outputMultiplier : 1);
297
395
 
298
396
  const standardCost =
@@ -302,8 +400,11 @@ export function calculateCostUsd(
302
400
  (unclassifiedCacheCreationInput / 1_000_000) * cacheCreationFallbackRate +
303
401
  (classifiedCacheCreationInput5m / 1_000_000) * cacheCreation5mRate +
304
402
  (classifiedCacheCreationInput1h / 1_000_000) * cacheCreation1hRate;
403
+
305
404
  const normalizedModel = model.split("/").pop() ?? model;
405
+
306
406
  return (
307
- standardCost * (serviceTier === "fast" ? (OPENAI_FAST_MULTIPLIERS[normalizedModel] ?? 1) : 1)
407
+ standardCost *
408
+ (serviceTier === "fast" ? (OPENAI_FAST_MULTIPLIERS.get(normalizedModel) ?? 1) : 1)
308
409
  );
309
410
  }