@theokit/sdk 4.24.0 → 4.26.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 (382) hide show
  1. package/dist/a2a/index.cjs +10 -171
  2. package/dist/a2a/index.cjs.map +1 -1
  3. package/dist/a2a/index.js +3 -170
  4. package/dist/a2a/index.js.map +1 -1
  5. package/dist/agent-factory-registry-UU46BUMU.cjs +16 -0
  6. package/dist/agent-factory-registry-UU46BUMU.cjs.map +1 -0
  7. package/dist/agent-factory-registry-ZVTABLEY.js +3 -0
  8. package/dist/agent-factory-registry-ZVTABLEY.js.map +1 -0
  9. package/dist/auth/index.cjs +63 -367
  10. package/dist/auth/index.cjs.map +1 -1
  11. package/dist/auth/index.js +6 -342
  12. package/dist/auth/index.js.map +1 -1
  13. package/dist/batch-2FSD2UNL.cjs +244 -0
  14. package/dist/batch-2FSD2UNL.cjs.map +1 -0
  15. package/dist/batch-MR2HKYMS.js +241 -0
  16. package/dist/batch-MR2HKYMS.js.map +1 -0
  17. package/dist/chunk-2HRYBRD7.cjs +31 -0
  18. package/dist/chunk-2HRYBRD7.cjs.map +1 -0
  19. package/dist/chunk-2MF3IE2D.cjs +2863 -0
  20. package/dist/chunk-2MF3IE2D.cjs.map +1 -0
  21. package/dist/chunk-2ONFGMBV.js +6 -0
  22. package/dist/chunk-2ONFGMBV.js.map +1 -0
  23. package/dist/chunk-2SFBB54R.js +23 -0
  24. package/dist/chunk-2SFBB54R.js.map +1 -0
  25. package/dist/chunk-2XLKLVVR.js +18 -0
  26. package/dist/chunk-2XLKLVVR.js.map +1 -0
  27. package/dist/chunk-4SXHEZIV.cjs +240 -0
  28. package/dist/chunk-4SXHEZIV.cjs.map +1 -0
  29. package/dist/chunk-4VPXM6UU.js +10 -0
  30. package/dist/chunk-4VPXM6UU.js.map +1 -0
  31. package/dist/chunk-4WL52CXU.cjs +148 -0
  32. package/dist/chunk-4WL52CXU.cjs.map +1 -0
  33. package/dist/chunk-5NBUH3NO.js +39 -0
  34. package/dist/chunk-5NBUH3NO.js.map +1 -0
  35. package/dist/chunk-5PZMMF4H.js +43 -0
  36. package/dist/chunk-5PZMMF4H.js.map +1 -0
  37. package/dist/chunk-6CLRANZA.js +289 -0
  38. package/dist/chunk-6CLRANZA.js.map +1 -0
  39. package/dist/chunk-6JSIEDKL.cjs +121 -0
  40. package/dist/chunk-6JSIEDKL.cjs.map +1 -0
  41. package/dist/chunk-6M4ODB2V.cjs +145 -0
  42. package/dist/chunk-6M4ODB2V.cjs.map +1 -0
  43. package/dist/chunk-6X6ID4MO.js +20 -0
  44. package/dist/chunk-6X6ID4MO.js.map +1 -0
  45. package/dist/chunk-77FOZCOT.js +165 -0
  46. package/dist/chunk-77FOZCOT.js.map +1 -0
  47. package/dist/chunk-7AD3ZTZL.js +25 -0
  48. package/dist/chunk-7AD3ZTZL.js.map +1 -0
  49. package/dist/chunk-7GFX45DD.js +57 -0
  50. package/dist/chunk-7GFX45DD.js.map +1 -0
  51. package/dist/chunk-7S7KKUO6.cjs +45 -0
  52. package/dist/chunk-7S7KKUO6.cjs.map +1 -0
  53. package/dist/chunk-7W7ZWMLQ.js +99 -0
  54. package/dist/chunk-7W7ZWMLQ.js.map +1 -0
  55. package/dist/chunk-A44COQJJ.cjs +353 -0
  56. package/dist/chunk-A44COQJJ.cjs.map +1 -0
  57. package/dist/chunk-AKSBP7OO.js +185 -0
  58. package/dist/chunk-AKSBP7OO.js.map +1 -0
  59. package/dist/chunk-ANIZEWTU.cjs +196 -0
  60. package/dist/chunk-ANIZEWTU.cjs.map +1 -0
  61. package/dist/chunk-BEURCLDV.cjs +139 -0
  62. package/dist/chunk-BEURCLDV.cjs.map +1 -0
  63. package/dist/chunk-BFWPZMG7.js +379 -0
  64. package/dist/chunk-BFWPZMG7.js.map +1 -0
  65. package/dist/chunk-BUUUWQMB.cjs +34 -0
  66. package/dist/chunk-BUUUWQMB.cjs.map +1 -0
  67. package/dist/chunk-BV2MWEMV.cjs +26 -0
  68. package/dist/chunk-BV2MWEMV.cjs.map +1 -0
  69. package/dist/chunk-BWT67BI4.cjs +268 -0
  70. package/dist/chunk-BWT67BI4.cjs.map +1 -0
  71. package/dist/chunk-BXV2QUIC.js +191 -0
  72. package/dist/chunk-BXV2QUIC.js.map +1 -0
  73. package/dist/chunk-C6Y6CWYD.cjs +44 -0
  74. package/dist/chunk-C6Y6CWYD.cjs.map +1 -0
  75. package/dist/chunk-C7PICHRF.cjs +68 -0
  76. package/dist/chunk-C7PICHRF.cjs.map +1 -0
  77. package/dist/chunk-CAH3G4IS.js +13 -0
  78. package/dist/chunk-CAH3G4IS.js.map +1 -0
  79. package/dist/chunk-D42XHI4O.cjs +565 -0
  80. package/dist/chunk-D42XHI4O.cjs.map +1 -0
  81. package/dist/chunk-DGRZNMTU.js +104 -0
  82. package/dist/chunk-DGRZNMTU.js.map +1 -0
  83. package/dist/chunk-DUK5WMKJ.js +71 -0
  84. package/dist/chunk-DUK5WMKJ.js.map +1 -0
  85. package/dist/chunk-EEZ7CFMM.js +14 -0
  86. package/dist/chunk-EEZ7CFMM.js.map +1 -0
  87. package/dist/chunk-EPYZOCOL.cjs +82 -0
  88. package/dist/chunk-EPYZOCOL.cjs.map +1 -0
  89. package/dist/chunk-EVADEGM7.cjs +168 -0
  90. package/dist/chunk-EVADEGM7.cjs.map +1 -0
  91. package/dist/chunk-FD2UT76F.js +3 -0
  92. package/dist/chunk-FD2UT76F.js.map +1 -0
  93. package/dist/chunk-FV3YEMQ7.js +179 -0
  94. package/dist/chunk-FV3YEMQ7.js.map +1 -0
  95. package/dist/chunk-G2F67XUR.cjs +184 -0
  96. package/dist/chunk-G2F67XUR.cjs.map +1 -0
  97. package/dist/chunk-G6GO6BXD.js +994 -0
  98. package/dist/chunk-G6GO6BXD.js.map +1 -0
  99. package/dist/chunk-GIW4L6HY.cjs +27 -0
  100. package/dist/chunk-GIW4L6HY.cjs.map +1 -0
  101. package/dist/chunk-GJAGKFTR.js +74 -0
  102. package/dist/chunk-GJAGKFTR.js.map +1 -0
  103. package/dist/chunk-HFPGOTVF.cjs +324 -0
  104. package/dist/chunk-HFPGOTVF.cjs.map +1 -0
  105. package/dist/chunk-HRA3CPGG.js +486 -0
  106. package/dist/chunk-HRA3CPGG.js.map +1 -0
  107. package/dist/chunk-HZQEDNF6.js +66 -0
  108. package/dist/chunk-HZQEDNF6.js.map +1 -0
  109. package/dist/chunk-IT3PWBW4.cjs +19 -0
  110. package/dist/chunk-IT3PWBW4.cjs.map +1 -0
  111. package/dist/chunk-JD74LN7R.cjs +171 -0
  112. package/dist/chunk-JD74LN7R.cjs.map +1 -0
  113. package/dist/chunk-JTFYYKDT.js +135 -0
  114. package/dist/chunk-JTFYYKDT.js.map +1 -0
  115. package/dist/chunk-K2BQQ445.js +30 -0
  116. package/dist/chunk-K2BQQ445.js.map +1 -0
  117. package/dist/chunk-KAP4GJHO.js +546 -0
  118. package/dist/chunk-KAP4GJHO.js.map +1 -0
  119. package/dist/chunk-KDNBTPY2.js +458 -0
  120. package/dist/chunk-KDNBTPY2.js.map +1 -0
  121. package/dist/chunk-KIO7QFIV.cjs +223 -0
  122. package/dist/chunk-KIO7QFIV.cjs.map +1 -0
  123. package/dist/chunk-KSKU6JY6.cjs +71 -0
  124. package/dist/chunk-KSKU6JY6.cjs.map +1 -0
  125. package/dist/chunk-LSLPF6OI.cjs +192 -0
  126. package/dist/chunk-LSLPF6OI.cjs.map +1 -0
  127. package/dist/chunk-LU7VALW5.js +312 -0
  128. package/dist/chunk-LU7VALW5.js.map +1 -0
  129. package/dist/chunk-LUSXDZPV.cjs +296 -0
  130. package/dist/chunk-LUSXDZPV.cjs.map +1 -0
  131. package/dist/chunk-M72RJVPC.js +69 -0
  132. package/dist/chunk-M72RJVPC.js.map +1 -0
  133. package/dist/chunk-MQLCZ4HJ.cjs +1010 -0
  134. package/dist/chunk-MQLCZ4HJ.cjs.map +1 -0
  135. package/dist/chunk-MUUQ2WFJ.cjs +4 -0
  136. package/dist/chunk-MUUQ2WFJ.cjs.map +1 -0
  137. package/dist/chunk-MZ5ZRORA.cjs +496 -0
  138. package/dist/chunk-MZ5ZRORA.cjs.map +1 -0
  139. package/dist/chunk-N24XBYNX.cjs +140 -0
  140. package/dist/chunk-N24XBYNX.cjs.map +1 -0
  141. package/dist/chunk-NINIJCHU.cjs +23 -0
  142. package/dist/chunk-NINIJCHU.cjs.map +1 -0
  143. package/dist/chunk-NRSH7RJY.js +2841 -0
  144. package/dist/chunk-NRSH7RJY.js.map +1 -0
  145. package/dist/chunk-OIYQBUW4.cjs +111 -0
  146. package/dist/chunk-OIYQBUW4.cjs.map +1 -0
  147. package/dist/chunk-PNVDQL5Y.cjs +15 -0
  148. package/dist/chunk-PNVDQL5Y.cjs.map +1 -0
  149. package/dist/chunk-POQT2OIF.js +214 -0
  150. package/dist/chunk-POQT2OIF.js.map +1 -0
  151. package/dist/chunk-PSJN532Q.js +10573 -0
  152. package/dist/chunk-PSJN532Q.js.map +1 -0
  153. package/dist/chunk-QUTUJ6P6.cjs +76 -0
  154. package/dist/chunk-QUTUJ6P6.cjs.map +1 -0
  155. package/dist/chunk-R43CNCES.cjs +460 -0
  156. package/dist/chunk-R43CNCES.cjs.map +1 -0
  157. package/dist/chunk-S2BBRVQX.js +68 -0
  158. package/dist/chunk-S2BBRVQX.js.map +1 -0
  159. package/dist/chunk-S5RCBTSF.js +145 -0
  160. package/dist/chunk-S5RCBTSF.js.map +1 -0
  161. package/dist/chunk-S7OEXQMI.cjs +136 -0
  162. package/dist/chunk-S7OEXQMI.cjs.map +1 -0
  163. package/dist/chunk-SKWVAQAY.js +129 -0
  164. package/dist/chunk-SKWVAQAY.js.map +1 -0
  165. package/dist/chunk-SQLZ7ONU.js +152 -0
  166. package/dist/chunk-SQLZ7ONU.js.map +1 -0
  167. package/dist/chunk-TIZ4TS5V.cjs +72 -0
  168. package/dist/chunk-TIZ4TS5V.cjs.map +1 -0
  169. package/dist/chunk-TQKCU7CL.js +142 -0
  170. package/dist/chunk-TQKCU7CL.js.map +1 -0
  171. package/dist/chunk-U54XCYG3.js +116 -0
  172. package/dist/chunk-U54XCYG3.js.map +1 -0
  173. package/dist/chunk-U6QGZHPN.js +29 -0
  174. package/dist/chunk-U6QGZHPN.js.map +1 -0
  175. package/dist/chunk-UCFONJBG.js +79 -0
  176. package/dist/chunk-UCFONJBG.js.map +1 -0
  177. package/dist/chunk-UJ7IQJAG.js +141 -0
  178. package/dist/chunk-UJ7IQJAG.js.map +1 -0
  179. package/dist/chunk-UVNG67DG.js +253 -0
  180. package/dist/chunk-UVNG67DG.js.map +1 -0
  181. package/dist/chunk-V4XRLPEF.js +25 -0
  182. package/dist/chunk-V4XRLPEF.js.map +1 -0
  183. package/dist/chunk-VJ26EKGJ.cjs +28 -0
  184. package/dist/chunk-VJ26EKGJ.cjs.map +1 -0
  185. package/dist/chunk-VK7MAV65.cjs +90 -0
  186. package/dist/chunk-VK7MAV65.cjs.map +1 -0
  187. package/dist/chunk-VYCKUKPA.cjs +106 -0
  188. package/dist/chunk-VYCKUKPA.cjs.map +1 -0
  189. package/dist/chunk-VYHJZVL5.cjs +29 -0
  190. package/dist/chunk-VYHJZVL5.cjs.map +1 -0
  191. package/dist/chunk-WA3FO4R7.js +155 -0
  192. package/dist/chunk-WA3FO4R7.js.map +1 -0
  193. package/dist/chunk-WJVHMTKB.cjs +12 -0
  194. package/dist/chunk-WJVHMTKB.cjs.map +1 -0
  195. package/dist/chunk-WLKFWQSJ.js +333 -0
  196. package/dist/chunk-WLKFWQSJ.js.map +1 -0
  197. package/dist/chunk-WPZTYOUX.cjs +59 -0
  198. package/dist/chunk-WPZTYOUX.cjs.map +1 -0
  199. package/dist/chunk-X2FR4OIT.js +27 -0
  200. package/dist/chunk-X2FR4OIT.js.map +1 -0
  201. package/dist/chunk-XIG2IE3L.js +134 -0
  202. package/dist/chunk-XIG2IE3L.js.map +1 -0
  203. package/dist/chunk-YLQQX5W2.cjs +20 -0
  204. package/dist/chunk-YLQQX5W2.cjs.map +1 -0
  205. package/dist/chunk-YPEPCZHF.cjs +147 -0
  206. package/dist/chunk-YPEPCZHF.cjs.map +1 -0
  207. package/dist/chunk-YPQF26X7.cjs +8 -0
  208. package/dist/chunk-YPQF26X7.cjs.map +1 -0
  209. package/dist/chunk-YU6KON2I.cjs +160 -0
  210. package/dist/chunk-YU6KON2I.cjs.map +1 -0
  211. package/dist/chunk-Z2OC3UIW.cjs +388 -0
  212. package/dist/chunk-Z2OC3UIW.cjs.map +1 -0
  213. package/dist/chunk-ZUBIEQJF.cjs +10590 -0
  214. package/dist/chunk-ZUBIEQJF.cjs.map +1 -0
  215. package/dist/chunk-ZZWTY3RX.js +230 -0
  216. package/dist/chunk-ZZWTY3RX.js.map +1 -0
  217. package/dist/compact-session-OO2GD76G.js +17 -0
  218. package/dist/compact-session-OO2GD76G.js.map +1 -0
  219. package/dist/compact-session-OO7NVWPB.cjs +54 -0
  220. package/dist/compact-session-OO7NVWPB.cjs.map +1 -0
  221. package/dist/compaction.cjs +54 -303
  222. package/dist/compaction.cjs.map +1 -1
  223. package/dist/compaction.js +3 -292
  224. package/dist/compaction.js.map +1 -1
  225. package/dist/concurrency.cjs +9 -81
  226. package/dist/concurrency.cjs.map +1 -1
  227. package/dist/concurrency.js +5 -80
  228. package/dist/concurrency.js.map +1 -1
  229. package/dist/context-GWANQLX4.js +5 -0
  230. package/dist/context-GWANQLX4.js.map +1 -0
  231. package/dist/context-KNWVTZSY.cjs +22 -0
  232. package/dist/context-KNWVTZSY.cjs.map +1 -0
  233. package/dist/{cron-x3muPNgg.d.cts → cron-D0JKR-yX.d.cts} +2 -1
  234. package/dist/{cron-B_NkE_VM.d.ts → cron-DivRaEmN.d.ts} +2 -1
  235. package/dist/cron.cjs +44 -20676
  236. package/dist/cron.cjs.map +1 -1
  237. package/dist/cron.d.cts +1 -1
  238. package/dist/cron.d.ts +1 -1
  239. package/dist/cron.js +38 -20676
  240. package/dist/cron.js.map +1 -1
  241. package/dist/errors.cjs +78 -470
  242. package/dist/errors.cjs.map +1 -1
  243. package/dist/errors.d.ts +3 -424
  244. package/dist/errors.js +2 -455
  245. package/dist/errors.js.map +1 -1
  246. package/dist/eval.cjs +72 -20411
  247. package/dist/eval.cjs.map +1 -1
  248. package/dist/eval.js +59 -20402
  249. package/dist/eval.js.map +1 -1
  250. package/dist/executor-ORJS5GV2.js +981 -0
  251. package/dist/executor-ORJS5GV2.js.map +1 -0
  252. package/dist/executor-Y4MKPIUD.cjs +985 -0
  253. package/dist/executor-Y4MKPIUD.cjs.map +1 -0
  254. package/dist/filesystem/index.cjs +7 -112
  255. package/dist/filesystem/index.cjs.map +1 -1
  256. package/dist/filesystem/index.js +4 -109
  257. package/dist/filesystem/index.js.map +1 -1
  258. package/dist/fork-agent-RSV4E3EA.js +61 -0
  259. package/dist/fork-agent-RSV4E3EA.js.map +1 -0
  260. package/dist/fork-agent-Y2IK2RYU.cjs +64 -0
  261. package/dist/fork-agent-Y2IK2RYU.cjs.map +1 -0
  262. package/dist/fs-session-store-KAUQYSGI.cjs +17 -0
  263. package/dist/fs-session-store-KAUQYSGI.cjs.map +1 -0
  264. package/dist/fs-session-store-ZKB5NN37.js +8 -0
  265. package/dist/fs-session-store-ZKB5NN37.js.map +1 -0
  266. package/dist/generate-object-H3RNAM6S.cjs +20 -0
  267. package/dist/generate-object-H3RNAM6S.cjs.map +1 -0
  268. package/dist/generate-object-YJPDV5BS.js +7 -0
  269. package/dist/generate-object-YJPDV5BS.js.map +1 -0
  270. package/dist/index-manager-CB6I7XFQ.cjs +19 -0
  271. package/dist/index-manager-CB6I7XFQ.cjs.map +1 -0
  272. package/dist/index-manager-L27Q3QAC.js +10 -0
  273. package/dist/index-manager-L27Q3QAC.js.map +1 -0
  274. package/dist/index.cjs +371 -22888
  275. package/dist/index.cjs.map +1 -1
  276. package/dist/index.d.cts +16 -21
  277. package/dist/index.d.ts +16 -21
  278. package/dist/index.js +92 -22713
  279. package/dist/index.js.map +1 -1
  280. package/dist/inject-session-6MJUSGZP.cjs +27 -0
  281. package/dist/inject-session-6MJUSGZP.cjs.map +1 -0
  282. package/dist/inject-session-KOFHS5K3.js +25 -0
  283. package/dist/inject-session-KOFHS5K3.js.map +1 -0
  284. package/dist/internal/judge/judge-call.d.ts +32 -19
  285. package/dist/internal/persistence/index.cjs +93 -508
  286. package/dist/internal/persistence/index.cjs.map +1 -1
  287. package/dist/internal/persistence/index.js +11 -489
  288. package/dist/internal/persistence/index.js.map +1 -1
  289. package/dist/internal/security/index.cjs +44 -361
  290. package/dist/internal/security/index.cjs.map +1 -1
  291. package/dist/internal/security/index.js +4 -355
  292. package/dist/internal/security/index.js.map +1 -1
  293. package/dist/judge-call-CEQ3FYYD.js +126 -0
  294. package/dist/judge-call-CEQ3FYYD.js.map +1 -0
  295. package/dist/judge-call-QG4WZ7F3.cjs +130 -0
  296. package/dist/judge-call-QG4WZ7F3.cjs.map +1 -0
  297. package/dist/models.cjs +24 -919
  298. package/dist/models.cjs.map +1 -1
  299. package/dist/models.js +11 -907
  300. package/dist/models.js.map +1 -1
  301. package/dist/oauth-transaction-store-7CKHPQRN.cjs +32 -0
  302. package/dist/oauth-transaction-store-7CKHPQRN.cjs.map +1 -0
  303. package/dist/oauth-transaction-store-W74I6EFD.js +3 -0
  304. package/dist/oauth-transaction-store-W74I6EFD.js.map +1 -0
  305. package/dist/path-safety.cjs +31 -200
  306. package/dist/path-safety.cjs.map +1 -1
  307. package/dist/path-safety.js +3 -197
  308. package/dist/path-safety.js.map +1 -1
  309. package/dist/persistence.cjs +73 -393
  310. package/dist/persistence.cjs.map +1 -1
  311. package/dist/persistence.js +9 -381
  312. package/dist/persistence.js.map +1 -1
  313. package/dist/project.cjs +8 -112
  314. package/dist/project.cjs.map +1 -1
  315. package/dist/project.js +6 -110
  316. package/dist/project.js.map +1 -1
  317. package/dist/registry-34IWWDQQ.js +9 -0
  318. package/dist/registry-34IWWDQQ.js.map +1 -0
  319. package/dist/registry-APYDISL6.cjs +46 -0
  320. package/dist/registry-APYDISL6.cjs.map +1 -0
  321. package/dist/retry.cjs +7 -87
  322. package/dist/retry.cjs.map +1 -1
  323. package/dist/retry.js +3 -90
  324. package/dist/retry.js.map +1 -1
  325. package/dist/run-to-completion-J73I6IY4.cjs +48 -0
  326. package/dist/run-to-completion-J73I6IY4.cjs.map +1 -0
  327. package/dist/run-to-completion-JDPIUKSH.js +3 -0
  328. package/dist/run-to-completion-JDPIUKSH.js.map +1 -0
  329. package/dist/run-until-PNO3QQLI.cjs +180 -0
  330. package/dist/run-until-PNO3QQLI.cjs.map +1 -0
  331. package/dist/run-until-XLHEHRQM.js +177 -0
  332. package/dist/run-until-XLHEHRQM.js.map +1 -0
  333. package/dist/sandbox/index.cjs +35 -337
  334. package/dist/sandbox/index.cjs.map +1 -1
  335. package/dist/sandbox/index.js +7 -323
  336. package/dist/sandbox/index.js.map +1 -1
  337. package/dist/sanitize/index.cjs +5 -112
  338. package/dist/sanitize/index.cjs.map +1 -1
  339. package/dist/sanitize/index.js +1 -114
  340. package/dist/sanitize/index.js.map +1 -1
  341. package/dist/server/auth/index.cjs +35 -175
  342. package/dist/server/auth/index.cjs.map +1 -1
  343. package/dist/server/auth/index.js +7 -161
  344. package/dist/server/auth/index.js.map +1 -1
  345. package/dist/server/errors-envelope.cjs +17 -328
  346. package/dist/server/errors-envelope.cjs.map +1 -1
  347. package/dist/server/errors-envelope.js +4 -317
  348. package/dist/server/errors-envelope.js.map +1 -1
  349. package/dist/session-transcript-LPNZR3YS.cjs +46 -0
  350. package/dist/session-transcript-LPNZR3YS.cjs.map +1 -0
  351. package/dist/session-transcript-T7LGJUGW.js +5 -0
  352. package/dist/session-transcript-T7LGJUGW.js.map +1 -0
  353. package/dist/skills.cjs +12 -280
  354. package/dist/skills.cjs.map +1 -1
  355. package/dist/skills.js +4 -282
  356. package/dist/skills.js.map +1 -1
  357. package/dist/stream-object-QEQJJDTI.cjs +20 -0
  358. package/dist/stream-object-QEQJJDTI.cjs.map +1 -0
  359. package/dist/stream-object-WUQSSRY2.js +7 -0
  360. package/dist/stream-object-WUQSSRY2.js.map +1 -0
  361. package/dist/stream-to-completion-DFJ5T3BK.js +30 -0
  362. package/dist/stream-to-completion-DFJ5T3BK.js.map +1 -0
  363. package/dist/stream-to-completion-H2MHISSK.cjs +32 -0
  364. package/dist/stream-to-completion-H2MHISSK.cjs.map +1 -0
  365. package/dist/subagents.cjs +2 -8
  366. package/dist/subagents.cjs.map +1 -1
  367. package/dist/subagents.js +1 -7
  368. package/dist/subagents.js.map +1 -1
  369. package/dist/subscription/index.cjs +4 -17
  370. package/dist/subscription/index.cjs.map +1 -1
  371. package/dist/subscription/index.js +3 -16
  372. package/dist/subscription/index.js.map +1 -1
  373. package/dist/task-store.cjs +16 -258
  374. package/dist/task-store.cjs.map +1 -1
  375. package/dist/task-store.js +4 -259
  376. package/dist/task-store.js.map +1 -1
  377. package/dist/types/goal-events.d.ts +2 -1
  378. package/dist/workflow.cjs +71 -2797
  379. package/dist/workflow.cjs.map +1 -1
  380. package/dist/workflow.js +8 -2812
  381. package/dist/workflow.js.map +1 -1
  382. package/package.json +1 -1
package/dist/models.js CHANGED
@@ -1,182 +1,15 @@
1
- import { statSync, readFileSync, unlinkSync, mkdirSync, writeFileSync, renameSync, chmodSync, openSync, fsyncSync, closeSync } from 'fs';
2
- import { dirname, join } from 'path';
3
- import { fileURLToPath } from 'url';
4
- import { z } from 'zod';
1
+ import { Retry } from './chunk-M72RJVPC.js';
2
+ import { parseModelId } from './chunk-X2FR4OIT.js';
3
+ export { parseModelId } from './chunk-X2FR4OIT.js';
4
+ import { getCatalogModelInfo, registerBuiltins, catalogModelSchema, patchModelInfo, getProviderProfile, loadProviderCatalog } from './chunk-KAP4GJHO.js';
5
+ import './chunk-LU7VALW5.js';
6
+ import './chunk-5NBUH3NO.js';
7
+ import './chunk-WLKFWQSJ.js';
8
+ import './chunk-JTFYYKDT.js';
5
9
  import { createHash, randomBytes } from 'crypto';
10
+ import { statSync, readFileSync, unlinkSync, mkdirSync, writeFileSync, renameSync } from 'fs';
6
11
  import { homedir } from 'os';
7
-
8
- // src/internal/providers/catalog-loader.ts
9
-
10
- // src/internal/global-singleton.ts
11
- function globalSingleton(key, create) {
12
- const g = globalThis;
13
- const sym = Symbol.for(key);
14
- if (g[sym] === void 0) g[sym] = create();
15
- return g[sym];
16
- }
17
- var MODALITIES = ["text", "audio", "image", "video", "pdf"];
18
- var costSchema = z.object({
19
- /** USD per 1M tokens (models.dev convention). */
20
- input: z.number().nonnegative(),
21
- output: z.number().nonnegative(),
22
- cache_read: z.number().nonnegative().optional(),
23
- cache_write: z.number().nonnegative().optional()
24
- }).loose();
25
- var limitSchema = z.object({
26
- context: z.number().positive(),
27
- input: z.number().positive().optional(),
28
- output: z.number().positive().optional()
29
- }).loose();
30
- var modalitiesSchema = z.object({
31
- input: z.array(z.enum(MODALITIES)).optional(),
32
- output: z.array(z.enum(MODALITIES)).optional()
33
- }).loose();
34
- var catalogModelSchema = z.object({
35
- name: z.string().optional(),
36
- release_date: z.string().optional(),
37
- attachment: z.boolean().optional(),
38
- reasoning: z.boolean().optional(),
39
- temperature: z.boolean().optional(),
40
- tool_call: z.boolean().optional(),
41
- /** theokit extension — maps to ModelCapabilities.supportsStructuredOutput. */
42
- structured_output: z.boolean().optional(),
43
- /** theokit extension — maps to ModelCapabilities.supportsCacheControl. */
44
- cache_control: z.boolean().optional(),
45
- cost: costSchema.optional(),
46
- limit: limitSchema.optional(),
47
- modalities: modalitiesSchema.optional(),
48
- status: z.enum(["alpha", "beta", "deprecated"]).optional()
49
- }).loose();
50
-
51
- // src/internal/providers/registry.ts
52
- var REGISTRY = globalSingleton(
53
- "theokit-sdk.providers.registry",
54
- () => /* @__PURE__ */ new Map()
55
- );
56
- var ALIASES = globalSingleton("theokit-sdk.providers.aliases", () => /* @__PURE__ */ new Map());
57
- function registerProvider(profile) {
58
- if (REGISTRY.has(profile.name)) {
59
- process.stderr.write(`[theokit-sdk] Provider "${profile.name}" overridden by user plugin.
60
- `);
61
- }
62
- REGISTRY.set(profile.name, profile);
63
- for (const alias of profile.aliases ?? []) {
64
- const previous = ALIASES.get(alias);
65
- if (previous !== void 0 && previous !== profile.name) {
66
- process.stderr.write(
67
- `[theokit-sdk] Alias "${alias}" collision: was "${previous}", now "${profile.name}".
68
- `
69
- );
70
- }
71
- ALIASES.set(alias, profile.name);
72
- }
73
- }
74
- function getProviderProfile(name) {
75
- const canonical = ALIASES.get(name) ?? name;
76
- return REGISTRY.get(canonical);
77
- }
78
-
79
- // src/internal/providers/catalog-loader.ts
80
- var __dirname_resolved = dirname(fileURLToPath(import.meta.url));
81
- var modelInfoIndex = globalSingleton(
82
- "theokit-sdk.providers.model-info-index",
83
- () => /* @__PURE__ */ new Map()
84
- );
85
- var patchedModelKeys = globalSingleton(
86
- "theokit-sdk.providers.model-info-patched",
87
- () => /* @__PURE__ */ new Set()
88
- );
89
- var indexState = globalSingleton("theokit-sdk.providers.model-info-loaded", () => ({
90
- loaded: false
91
- }));
92
- function getCatalogModelInfo(key) {
93
- ensureModelIndexLoaded();
94
- return modelInfoIndex.get(key);
95
- }
96
- function patchModelInfo(key, model) {
97
- ensureModelIndexLoaded();
98
- const existing = modelInfoIndex.get(key);
99
- modelInfoIndex.set(key, existing === void 0 ? model : { ...existing, ...model });
100
- patchedModelKeys.add(key);
101
- }
102
- function ensureModelIndexLoaded() {
103
- if (indexState.loaded) return;
104
- indexState.loaded = true;
105
- try {
106
- const catalog = loadProviderCatalog();
107
- for (const entry of Object.values(catalog)) {
108
- indexEntryModels(entry);
109
- }
110
- } catch (err) {
111
- process.stderr.write(
112
- `[theokit-sdk] WARN: provider catalog unavailable (${err.message}) \u2014 per-model data disabled
113
- `
114
- );
115
- }
116
- }
117
- function indexEntryModels(entry) {
118
- if (entry.models === void 0 || typeof entry.models !== "object") return;
119
- for (const [modelId, raw] of Object.entries(entry.models)) {
120
- const parsed = catalogModelSchema.safeParse(raw);
121
- if (!parsed.success) {
122
- process.stderr.write(
123
- `[theokit-sdk] WARN: Skipping malformed catalog model "${entry.id}/${modelId}": ${parsed.error.issues[0]?.message ?? "invalid"}
124
- `
125
- );
126
- continue;
127
- }
128
- modelInfoIndex.set(`${entry.id}/${modelId}`, parsed.data);
129
- for (const alias of entry.aliases ?? []) {
130
- const key = `${alias}/${modelId}`;
131
- if (!modelInfoIndex.has(key)) modelInfoIndex.set(key, parsed.data);
132
- }
133
- }
134
- }
135
- function validateEntry(raw) {
136
- if (typeof raw.id !== "string" || typeof raw.displayName !== "string" || typeof raw.apiMode !== "string" || typeof raw.authType !== "string" || typeof raw.baseUrl !== "string" || !Array.isArray(raw.envVars) || !Array.isArray(raw.fallbackModels) || raw.capabilities == null || typeof raw.capabilities !== "object") {
137
- return null;
138
- }
139
- return raw;
140
- }
141
- function loadProviderCatalog(opts) {
142
- const catalogPath = join(__dirname_resolved, "provider-catalog.json");
143
- const rawText = readFileSync(catalogPath, "utf-8");
144
- let entries = JSON.parse(rawText);
145
- const result = {};
146
- for (const raw of entries) {
147
- const validated = validateEntry(raw);
148
- if (validated === null) {
149
- process.stderr.write(
150
- `[theokit-sdk] WARN: Skipping malformed catalog entry: ${JSON.stringify(raw).slice(0, 100)}
151
- `
152
- );
153
- continue;
154
- }
155
- result[validated.id] = validated;
156
- }
157
- return result;
158
- }
159
- function registerCatalogProviders(opts) {
160
- const catalog = loadProviderCatalog();
161
- for (const entry of Object.values(catalog)) {
162
- if (getProviderProfile(entry.id) !== void 0) continue;
163
- if (entry.aliases?.some((a) => getProviderProfile(a) !== void 0)) continue;
164
- const profile = {
165
- name: entry.id,
166
- apiMode: entry.apiMode,
167
- authType: entry.authType,
168
- baseUrl: entry.baseUrl,
169
- envVars: entry.envVars,
170
- fallbackModels: entry.fallbackModels,
171
- displayName: entry.displayName,
172
- aliases: entry.aliases,
173
- modelsUrl: entry.modelsUrl,
174
- hostname: entry.hostname,
175
- extraHeaders: entry.extraHeaders
176
- };
177
- registerProvider(profile);
178
- }
179
- }
12
+ import { join, dirname } from 'path';
180
13
 
181
14
  // src/internal/llm/model-capabilities.ts
182
15
  var CONSERVATIVE_DEFAULTS = {
@@ -227,30 +60,6 @@ function inferVendorPrefix(bare) {
227
60
  return bare;
228
61
  }
229
62
 
230
- // src/internal/llm/model-identifier.ts
231
- var PROVIDER_ALIASES = {
232
- "llama-cpp": "llamacpp",
233
- "llama.cpp": "llamacpp",
234
- "lm-studio": "lmstudio",
235
- lm_studio: "lmstudio"
236
- };
237
- function parseModelId(modelId) {
238
- if (modelId === void 0 || modelId.length === 0) {
239
- return { provider: void 0, name: "" };
240
- }
241
- const slash = modelId.indexOf("/");
242
- if (slash <= 0 || slash === modelId.length - 1) {
243
- return { provider: void 0, name: modelId };
244
- }
245
- const rawProvider = modelId.slice(0, slash).trim().toLowerCase();
246
- const name = modelId.slice(slash + 1).trim();
247
- if (rawProvider.length === 0 || name.length === 0) {
248
- return { provider: void 0, name: modelId };
249
- }
250
- const canonical = PROVIDER_ALIASES[rawProvider] ?? rawProvider;
251
- return { provider: canonical, name };
252
- }
253
-
254
63
  // src/internal/llm/model-option.ts
255
64
  var ACRONYMS = /* @__PURE__ */ new Set(["gpt", "ai", "hd", "ui", "api", "sdk", "llm", "xl"]);
256
65
  function prettyToken(token) {
@@ -276,711 +85,6 @@ function toModelOption(modelId) {
276
85
  provider: parseModelId(modelId).provider
277
86
  };
278
87
  }
279
-
280
- // src/errors.ts
281
- var TheokitAgentError = class extends Error {
282
- name = "TheokitAgentError";
283
- isRetryable;
284
- code;
285
- protoErrorCode;
286
- metadata;
287
- constructor(message, options = {}) {
288
- super(message, options.cause !== void 0 ? { cause: options.cause } : void 0);
289
- this.isRetryable = options.isRetryable ?? false;
290
- if (options.code !== void 0) this.code = options.code;
291
- if (options.protoErrorCode !== void 0) this.protoErrorCode = options.protoErrorCode;
292
- if (options.metadata !== void 0) this.metadata = options.metadata;
293
- }
294
- };
295
- var AuthenticationError = class extends TheokitAgentError {
296
- name = "AuthenticationError";
297
- constructor(message, options = {}) {
298
- super(message, { ...options, isRetryable: false });
299
- }
300
- };
301
- var ConfigurationError = class extends TheokitAgentError {
302
- name = "ConfigurationError";
303
- constructor(message, options = {}) {
304
- super(message, { ...options, isRetryable: false });
305
- }
306
- };
307
- function isTransientError(err) {
308
- return err instanceof TheokitAgentError && err.isRetryable === true;
309
- }
310
-
311
- // src/internal/runtime/retry/with-retry.ts
312
- function defaultSleep(ms, signal) {
313
- return new Promise((resolve, reject) => {
314
- if (signal?.aborted) {
315
- reject(signal.reason instanceof Error ? signal.reason : new Error("withRetry: aborted"));
316
- return;
317
- }
318
- const timer = setTimeout(() => {
319
- signal?.removeEventListener("abort", onAbort);
320
- resolve();
321
- }, ms);
322
- function onAbort() {
323
- clearTimeout(timer);
324
- reject(signal?.reason instanceof Error ? signal.reason : new Error("withRetry: aborted"));
325
- }
326
- signal?.addEventListener("abort", onAbort, { once: true });
327
- });
328
- }
329
- function resolveRetryOptions(options) {
330
- const retries = options?.retries ?? 3;
331
- if (!Number.isInteger(retries) || retries < 0) {
332
- throw new ConfigurationError(
333
- `withRetry: retries must be a non-negative integer, got ${retries}`,
334
- { code: "invalid_retry_config" }
335
- );
336
- }
337
- return {
338
- retries,
339
- isRetryable: options?.isRetryable ?? isTransientError,
340
- initialDelayMs: options?.initialDelayMs ?? 100,
341
- maxDelayMs: options?.maxDelayMs ?? 3e4,
342
- backoffMultiplier: options?.backoffMultiplier ?? 2,
343
- rng: options?.rng ?? Math.random,
344
- sleep: options?.sleep ?? defaultSleep,
345
- signal: options?.signal
346
- };
347
- }
348
- function backoffMs(cfg, attempt) {
349
- const ceiling = Math.min(cfg.maxDelayMs, cfg.initialDelayMs * cfg.backoffMultiplier ** attempt);
350
- return Math.floor(cfg.rng() * ceiling);
351
- }
352
- async function withRetry(fn, options) {
353
- const cfg = resolveRetryOptions(options);
354
- let attempt = 0;
355
- for (; ; ) {
356
- try {
357
- return await fn();
358
- } catch (err) {
359
- if (attempt >= cfg.retries || !cfg.isRetryable(err)) throw err;
360
- await cfg.sleep(backoffMs(cfg, attempt), cfg.signal);
361
- attempt += 1;
362
- }
363
- }
364
- }
365
-
366
- // src/retry.ts
367
- var Retry = class {
368
- constructor() {
369
- }
370
- static create(fn, options) {
371
- return withRetry(fn, options);
372
- }
373
- };
374
-
375
- // src/internal/providers/builtin/anthropic.ts
376
- var ANTHROPIC = {
377
- name: "anthropic",
378
- apiMode: "anthropic_messages",
379
- envVars: ["ANTHROPIC_API_KEY"],
380
- authType: "api_key",
381
- baseUrl: "https://api.anthropic.com",
382
- modelsUrl: "https://api.anthropic.com/v1/models",
383
- hostname: "api.anthropic.com",
384
- fallbackModels: ["claude-opus-4-7", "claude-sonnet-4-6", "claude-haiku-4-5-20251001"],
385
- // M45 — the Anthropic beta-features header (interleaved thinking + fine-grained tool streaming). An
386
- // Anthropic API constant, adapted verbatim from OpenCode's anthropic plugin (MIT © 2025 opencode). The
387
- // SANCTIONED behavior delta of M45 (ADR D4) — consumed by the anthropic transport's extraHeaders wiring.
388
- extraHeaders: {
389
- "anthropic-beta": "interleaved-thinking-2025-05-14,fine-grained-tool-streaming-2025-05-14"
390
- }
391
- };
392
-
393
- // src/internal/providers/builtin/bedrock.ts
394
- var BEDROCK = {
395
- name: "bedrock",
396
- apiMode: "bedrock_anthropic",
397
- envVars: ["AWS_BEARER_TOKEN_BEDROCK"],
398
- authType: "aws_bearer",
399
- baseUrl: "https://bedrock-runtime.us-east-1.amazonaws.com",
400
- modelsUrl: void 0,
401
- hostname: "bedrock-runtime.amazonaws.com",
402
- fallbackModels: [
403
- "bedrock/us.anthropic.claude-sonnet-4-5-v1:0",
404
- "bedrock/us.anthropic.claude-opus-4-7-v1:0",
405
- "bedrock/global.anthropic.claude-haiku-4-5-v1:0"
406
- ]
407
- };
408
-
409
- // src/internal/providers/builtin/openai-compatible.ts
410
- function openAiCompatibleProfile(p) {
411
- return {
412
- apiMode: "chat_completions",
413
- authType: "api_key",
414
- fallbackModels: [],
415
- ...p
416
- };
417
- }
418
-
419
- // src/internal/providers/builtin/cerebras.ts
420
- var CEREBRAS = openAiCompatibleProfile({
421
- name: "cerebras",
422
- baseUrl: "https://api.cerebras.ai/v1",
423
- envVars: ["CEREBRAS_API_KEY"],
424
- fallbackModels: ["gpt-oss-120b", "zai-glm-4.7"],
425
- extraHeaders: { "X-Cerebras-3rd-Party-Integration": "theokit" },
426
- hostname: "api.cerebras.ai"
427
- });
428
-
429
- // src/internal/providers/builtin/cohere.ts
430
- var COHERE = openAiCompatibleProfile({
431
- name: "cohere",
432
- baseUrl: "https://api.cohere.ai/compatibility/v1",
433
- envVars: ["COHERE_API_KEY", "CO_API_KEY"],
434
- fallbackModels: ["command-a-03-2025"],
435
- hostname: "api.cohere.ai"
436
- });
437
-
438
- // src/internal/providers/builtin/deepinfra.ts
439
- var DEEPINFRA = openAiCompatibleProfile({
440
- name: "deepinfra",
441
- baseUrl: "https://api.deepinfra.com/v1/openai",
442
- envVars: ["DEEPINFRA_API_KEY"],
443
- fallbackModels: ["Qwen/Qwen3-32B"],
444
- hostname: "api.deepinfra.com"
445
- });
446
-
447
- // src/internal/providers/builtin/gemini.ts
448
- var GEMINI = {
449
- name: "gemini",
450
- apiMode: "chat_completions",
451
- envVars: ["OPENROUTER_API_KEY"],
452
- authType: "api_key",
453
- baseUrl: "https://openrouter.ai/api",
454
- hostname: "openrouter.ai",
455
- fallbackModels: ["google/gemini-2.0-flash-001"]
456
- };
457
-
458
- // src/internal/providers/builtin/google.ts
459
- var GOOGLE = openAiCompatibleProfile({
460
- name: "google",
461
- baseUrl: "https://generativelanguage.googleapis.com/v1beta/openai",
462
- envVars: ["GOOGLE_API_KEY", "GEMINI_API_KEY", "GOOGLE_GENERATIVE_AI_API_KEY"],
463
- fallbackModels: ["gemini-2.5-pro", "gemini-2.5-flash"],
464
- hostname: "generativelanguage.googleapis.com"
465
- });
466
-
467
- // src/internal/providers/builtin/groq.ts
468
- var GROQ = openAiCompatibleProfile({
469
- name: "groq",
470
- baseUrl: "https://api.groq.com/openai/v1",
471
- envVars: ["GROQ_API_KEY"],
472
- fallbackModels: ["llama-3.3-70b-versatile", "llama-3.1-8b-instant"],
473
- hostname: "api.groq.com"
474
- });
475
-
476
- // src/internal/providers/builtin/llamacpp.ts
477
- var LLAMACPP = {
478
- name: "llamacpp",
479
- aliases: ["llama-cpp", "llama.cpp"],
480
- apiMode: "chat_completions",
481
- envVars: ["LLAMACPP_API_KEY"],
482
- authType: "none",
483
- baseUrl: "http://localhost:8080",
484
- modelsUrl: "http://localhost:8080/v1/models",
485
- hostname: "localhost",
486
- fallbackModels: ["loaded-model"]
487
- };
488
-
489
- // src/internal/providers/builtin/lmstudio.ts
490
- var LMSTUDIO = {
491
- name: "lmstudio",
492
- aliases: ["lm-studio", "lm_studio"],
493
- apiMode: "chat_completions",
494
- envVars: ["LMSTUDIO_API_KEY"],
495
- authType: "none",
496
- baseUrl: "http://localhost:1234",
497
- modelsUrl: "http://localhost:1234/v1/models",
498
- hostname: "localhost",
499
- fallbackModels: ["loaded-model"]
500
- };
501
-
502
- // src/internal/providers/builtin/mistral.ts
503
- var MISTRAL = openAiCompatibleProfile({
504
- name: "mistral",
505
- baseUrl: "https://api.mistral.ai/v1",
506
- envVars: ["MISTRAL_API_KEY"],
507
- fallbackModels: ["mistral-large-latest", "codestral-latest"],
508
- hostname: "api.mistral.ai"
509
- });
510
-
511
- // src/internal/providers/builtin/ollama.ts
512
- var OLLAMA = {
513
- name: "ollama",
514
- apiMode: "chat_completions",
515
- envVars: ["OLLAMA_API_KEY"],
516
- authType: "none",
517
- baseUrl: "http://localhost:11434",
518
- modelsUrl: "http://localhost:11434/v1/models",
519
- hostname: "localhost",
520
- fallbackModels: ["llama3.2", "qwen2.5", "mistral"]
521
- };
522
-
523
- // src/internal/providers/builtin/openai.ts
524
- var OPENAI = {
525
- name: "openai",
526
- apiMode: "chat_completions",
527
- envVars: ["OPENAI_API_KEY"],
528
- authType: "api_key",
529
- baseUrl: "https://api.openai.com",
530
- modelsUrl: "https://api.openai.com/v1/models",
531
- hostname: "api.openai.com",
532
- fallbackModels: ["gpt-4o", "gpt-4o-mini"]
533
- };
534
- function credentialHome(config, env = {}) {
535
- const override = config.homeEnvVar !== void 0 ? env[config.homeEnvVar]?.trim() : void 0;
536
- return override !== void 0 && override.length > 0 ? override : join(config.home, config.dirName);
537
- }
538
- function authFilePath(config, env = {}) {
539
- return join(credentialHome(config, env), config.fileName);
540
- }
541
- var CredentialError = class extends AuthenticationError {
542
- // Field, not an assignment in the constructor: `AuthenticationError.name` is `override readonly`
543
- // (`errors.ts:174`), so `this.name = …` does not compile. Caught by `tsc`, not by vitest — the
544
- // suite was green with the broken assignment because the transpiler strips the type.
545
- name = "CredentialError";
546
- };
547
- var apiFileSchema = z.object({
548
- type: z.literal("api").optional(),
549
- provider: z.string().min(1).optional(),
550
- api_key: z.string()
551
- }).strict();
552
- var oauthFileSchema = z.object({
553
- type: z.literal("oauth"),
554
- provider: z.string().min(1),
555
- access: z.string().min(1),
556
- refresh: z.string().min(1),
557
- expires: z.number(),
558
- account_id: z.string().optional()
559
- }).strict();
560
- var fileSchema = z.union([oauthFileSchema, apiFileSchema]);
561
- function assertSecureModes(dirPath, path) {
562
- const dirMode = statSync(dirPath).mode & 511;
563
- if ((dirMode & 18) !== 0) {
564
- throw new CredentialError(
565
- `${dirPath} is writable by other users (mode ${dirMode.toString(8)}), so the credential file inside it can be replaced. Fix it with: chmod 700 ${dirPath}`
566
- );
567
- }
568
- const mode = statSync(path).mode & 511;
569
- if ((mode & 63) !== 0) {
570
- throw new CredentialError(
571
- `${path} is readable by other users (mode ${mode.toString(8)}). A credential file must not be. Fix it with: chmod 600 ${path}`
572
- );
573
- }
574
- }
575
- function describeUnionError(parsed, err, path) {
576
- const looksOAuth = typeof parsed === "object" && parsed !== null && parsed.type === "oauth";
577
- const specific = looksOAuth ? oauthFileSchema.safeParse(parsed) : apiFileSchema.safeParse(parsed);
578
- let issue;
579
- if (!specific.success) {
580
- issue = specific.error.issues[0];
581
- } else if (err instanceof z.ZodError) {
582
- issue = err.issues[0];
583
- }
584
- return new CredentialError(
585
- `${path}: ${issue?.message ?? String(err)} [${issue?.path.join(".") || "root"}]`
586
- );
587
- }
588
- function parseStoredFile(raw, path) {
589
- let parsed;
590
- try {
591
- parsed = JSON.parse(raw);
592
- } catch {
593
- throw new CredentialError(
594
- `${path} is not valid JSON. Expected: {"provider": "<name>", "api_key": "..."}`
595
- );
596
- }
597
- try {
598
- return fileSchema.parse(parsed);
599
- } catch (err) {
600
- throw describeUnionError(parsed, err, path);
601
- }
602
- }
603
- function readAuthFile(config, env = {}) {
604
- const path = authFilePath(config, env);
605
- let raw;
606
- try {
607
- raw = readFileSync(path, "utf8");
608
- } catch (err) {
609
- if (err.code === "ENOENT") return void 0;
610
- throw new CredentialError(`cannot read ${path}: ${err.message}`);
611
- }
612
- assertSecureModes(credentialHome(config, env), path);
613
- return parseStoredFile(raw, path);
614
- }
615
- function readStoredOAuth(config, env = {}) {
616
- const stored = readAuthFile(config, env);
617
- return stored !== void 0 && stored.type === "oauth" ? stored : void 0;
618
- }
619
- function isOAuthWrite(c) {
620
- return "type" in c && c.type === "oauth";
621
- }
622
- function buildStorePayload(cred) {
623
- if (isOAuthWrite(cred)) {
624
- if (cred.access.length === 0 || cred.refresh.length === 0) {
625
- throw new CredentialError(
626
- "refusing to write an oauth credential with an empty access/refresh token"
627
- );
628
- }
629
- return {
630
- type: "oauth",
631
- provider: cred.provider,
632
- access: cred.access,
633
- refresh: cred.refresh,
634
- expires: cred.expires,
635
- ...cred.account_id !== void 0 ? { account_id: cred.account_id } : {}
636
- };
637
- }
638
- if (typeof cred.apiKey !== "string" || cred.apiKey.length === 0) {
639
- throw new CredentialError("refusing to write an empty API key");
640
- }
641
- return { provider: cred.provider, api_key: cred.apiKey };
642
- }
643
- function writeCredential(cred, config, env = {}) {
644
- const payload = buildStorePayload(cred);
645
- const dir = credentialHome(config, env);
646
- mkdirSync(dir, { recursive: true, mode: 448 });
647
- chmodSync(dir, 448);
648
- const path = authFilePath(config, env);
649
- const tmp = `${path}.tmp-${randomBytes(8).toString("hex")}`;
650
- try {
651
- const fd = openSync(tmp, "wx", 384);
652
- try {
653
- writeFileSync(fd, `${JSON.stringify(payload, null, 2)}
654
- `);
655
- fsyncSync(fd);
656
- } finally {
657
- closeSync(fd);
658
- }
659
- chmodSync(tmp, 384);
660
- renameSync(tmp, path);
661
- } catch (err) {
662
- try {
663
- unlinkSync(tmp);
664
- } catch {
665
- }
666
- throw new CredentialError(`cannot write ${path}: ${err.message}`);
667
- }
668
- return path;
669
- }
670
-
671
- // src/server/auth/errors.ts
672
- var AuthCallbackError = class extends Error {
673
- name = "AuthCallbackError";
674
- code;
675
- constructor(code, message) {
676
- super(message ?? `OAuth callback error: ${code}`);
677
- this.code = code;
678
- }
679
- };
680
-
681
- // src/internal/auth/oauth-engine.ts
682
- var REFRESH_SKEW_MS = 6e4;
683
- function parseTokenResponse(body, now) {
684
- const b = body;
685
- if (typeof b.access_token !== "string" || b.access_token.length === 0) {
686
- throw new AuthCallbackError(
687
- "oauth_token_exchange_failed",
688
- "token response had no access_token"
689
- );
690
- }
691
- if (typeof b.refresh_token !== "string" || b.refresh_token.length === 0) {
692
- throw new AuthCallbackError(
693
- "oauth_token_exchange_failed",
694
- "token response had no refresh_token"
695
- );
696
- }
697
- const expiresIn = typeof b.expires_in === "number" ? b.expires_in : 3600;
698
- return {
699
- access: b.access_token,
700
- refresh: b.refresh_token,
701
- expires: now + expiresIn * 1e3,
702
- ...typeof b.account_id === "string" ? { accountId: b.account_id } : {}
703
- };
704
- }
705
- async function postGrant(config, form, deps) {
706
- let res;
707
- try {
708
- res = await deps.fetch(config.tokenEndpoint, {
709
- method: "POST",
710
- headers: { "content-type": "application/x-www-form-urlencoded", accept: "application/json" },
711
- body: new URLSearchParams(form).toString()
712
- });
713
- } catch (err) {
714
- throw new AuthCallbackError(
715
- "oauth_token_exchange_failed",
716
- `token endpoint request failed: ${err.message}`
717
- );
718
- }
719
- if (!res.ok) {
720
- throw new AuthCallbackError(
721
- "oauth_token_exchange_failed",
722
- `token endpoint returned HTTP ${res.status}`
723
- );
724
- }
725
- let json;
726
- try {
727
- json = await res.json();
728
- } catch {
729
- throw new AuthCallbackError("oauth_token_exchange_failed", "token response was not valid JSON");
730
- }
731
- return parseTokenResponse(json, deps.now());
732
- }
733
- function refreshOAuthTokens(config, refresh, deps) {
734
- return postGrant(
735
- config,
736
- { grant_type: "refresh_token", refresh_token: refresh, client_id: config.clientId },
737
- deps
738
- );
739
- }
740
- function persistOAuthTokens(provider, tokens, store, env = {}) {
741
- return writeCredential(
742
- {
743
- type: "oauth",
744
- provider,
745
- access: tokens.access,
746
- refresh: tokens.refresh,
747
- expires: tokens.expires,
748
- ...tokens.accountId !== void 0 ? { account_id: tokens.accountId } : {}
749
- },
750
- store,
751
- env
752
- );
753
- }
754
- var inFlightRefresh = /* @__PURE__ */ new Map();
755
- async function ensureFreshCredential(resolved, opts, deps) {
756
- if (resolved.kind !== "oauth") return resolved;
757
- const now = deps.now();
758
- if (resolved.expiresAt !== void 0 && resolved.expiresAt > now + REFRESH_SKEW_MS) {
759
- return resolved;
760
- }
761
- const env = opts.env ?? {};
762
- const path = authFilePath(opts.store, env);
763
- let refresh = inFlightRefresh.get(path);
764
- if (refresh === void 0) {
765
- refresh = (async () => {
766
- const stored = readStoredOAuth(opts.store, env);
767
- if (stored === void 0) {
768
- throw new AuthCallbackError(
769
- "oauth_token_exchange_failed",
770
- "no stored oauth credential to refresh"
771
- );
772
- }
773
- const fresh2 = await refreshOAuthTokens(opts.config, stored.refresh, deps);
774
- const merged = {
775
- ...fresh2,
776
- accountId: fresh2.accountId ?? stored.account_id
777
- };
778
- persistOAuthTokens(resolved.provider, merged, opts.store, env);
779
- return merged;
780
- })();
781
- inFlightRefresh.set(path, refresh);
782
- refresh.finally(() => inFlightRefresh.delete(path)).catch(() => {
783
- });
784
- }
785
- const fresh = await refresh;
786
- return {
787
- kind: "oauth",
788
- provider: resolved.provider,
789
- apiKey: fresh.access,
790
- source: resolved.source,
791
- inferred: false,
792
- expiresAt: fresh.expires
793
- };
794
- }
795
-
796
- // src/internal/auth/resolve-credential.ts
797
- async function resolveOAuth(stored, path, opts, env) {
798
- if (stored.provider !== opts.provider) return void 0;
799
- const base = {
800
- kind: "oauth",
801
- provider: opts.provider,
802
- apiKey: stored.access,
803
- source: path,
804
- inferred: false,
805
- expiresAt: stored.expires
806
- };
807
- if (opts.oauth === void 0) return base;
808
- const deps = {
809
- fetch: opts.deps?.fetch ?? fetch,
810
- now: opts.deps?.now ?? (() => Date.now())
811
- };
812
- return ensureFreshCredential(base, { config: opts.oauth, store: opts.store, env }, deps);
813
- }
814
- async function resolveCredential(opts) {
815
- const env = opts.env ?? {};
816
- const stored = readAuthFile(opts.store, env);
817
- if (stored === void 0) return void 0;
818
- const path = authFilePath(opts.store, env);
819
- if (stored.type === "oauth") {
820
- return resolveOAuth(stored, path, opts, env);
821
- }
822
- if (stored.api_key.length === 0) return void 0;
823
- if (stored.provider !== opts.provider) return void 0;
824
- return {
825
- kind: "api",
826
- provider: opts.provider,
827
- apiKey: stored.api_key,
828
- source: path,
829
- inferred: false
830
- };
831
- }
832
-
833
- // src/internal/providers/builtin/openai-chatgpt.ts
834
- var DEFAULT_STORE = {
835
- home: homedir(),
836
- dirName: ".theokit",
837
- fileName: "auth.json",
838
- homeEnvVar: "THEOKIT_AUTH_HOME"
839
- };
840
- var OPENAI_OAUTH_CONFIG = {
841
- provider: "openai",
842
- authorizeEndpoint: "https://auth.openai.com/oauth/authorize",
843
- tokenEndpoint: "https://auth.openai.com/oauth/token",
844
- clientId: "app_EMoamEEZ73f0CkXaXp7hrann",
845
- scopes: ["openid", "profile", "email", "offline_access"],
846
- redirectUri: "https://auth.openai.com/deviceauth/callback"
847
- };
848
- function codexFetch() {
849
- return (async (input, init) => {
850
- const env = process.env;
851
- const resolved = await resolveCredential({
852
- provider: "openai",
853
- store: DEFAULT_STORE,
854
- oauth: OPENAI_OAUTH_CONFIG,
855
- env
856
- });
857
- if (resolved === void 0) {
858
- throw new Error(
859
- 'openai-chatgpt: no ChatGPT credential found \u2014 run the OpenAI device login (e.g. "/login openai") first.'
860
- );
861
- }
862
- const accountId = readStoredOAuth(DEFAULT_STORE, env)?.account_id;
863
- const headers = new Headers(init?.headers);
864
- headers.set("authorization", `Bearer ${resolved.apiKey}`);
865
- if (accountId !== void 0) headers.set("ChatGPT-Account-Id", accountId);
866
- return fetch(input, { ...init, headers });
867
- });
868
- }
869
- var OPENAI_CHATGPT = {
870
- name: "openai-chatgpt",
871
- apiMode: "responses_api",
872
- authType: "oauth_device_code",
873
- baseUrl: "https://chatgpt.com/backend-api/codex",
874
- envVars: [],
875
- fallbackModels: [
876
- "openai-chatgpt/gpt-5.4",
877
- "openai-chatgpt/gpt-5.4-mini",
878
- "openai-chatgpt/gpt-5.5"
879
- ],
880
- extraHeaders: { originator: "codex_cli_rs" },
881
- transform: {
882
- // Only `fetch` (async) can await the credential refresh; `headers` is sync and cannot.
883
- fetch: () => codexFetch()
884
- }
885
- };
886
-
887
- // src/internal/providers/builtin/openrouter.ts
888
- var OPENROUTER = {
889
- name: "openrouter",
890
- apiMode: "chat_completions",
891
- aliases: ["or"],
892
- // Ordered fallback (EC-10): OPENROUTER_API_KEY preferred, OPENAI_API_KEY as compat.
893
- envVars: ["OPENROUTER_API_KEY", "OPENAI_API_KEY"],
894
- authType: "api_key",
895
- baseUrl: "https://openrouter.ai/api",
896
- modelsUrl: "https://openrouter.ai/api/v1/models",
897
- hostname: "openrouter.ai",
898
- // M45 — models refreshed (claude-3-haiku retired upstream).
899
- fallbackModels: ["openai/gpt-4o-mini", "anthropic/claude-haiku-4-5"],
900
- // M45 — OpenRouter app-attribution headers (mechanism from OpenCode's openrouter plugin, MIT; VALUES are
901
- // theokit's own — copying another app's referer would misattribute traffic).
902
- extraHeaders: { "HTTP-Referer": "https://usetheo.dev", "X-Title": "theokit" }
903
- };
904
-
905
- // src/internal/providers/builtin/perplexity.ts
906
- var PERPLEXITY = openAiCompatibleProfile({
907
- name: "perplexity",
908
- baseUrl: "https://api.perplexity.ai",
909
- chatCompletionsPath: "/chat/completions",
910
- envVars: ["PERPLEXITY_API_KEY"],
911
- fallbackModels: ["sonar-pro", "sonar"],
912
- hostname: "api.perplexity.ai"
913
- });
914
-
915
- // src/internal/providers/builtin/together.ts
916
- var TOGETHER = openAiCompatibleProfile({
917
- name: "together",
918
- aliases: ["togetherai"],
919
- baseUrl: "https://api.together.xyz/v1",
920
- envVars: ["TOGETHER_API_KEY"],
921
- fallbackModels: ["Qwen/Qwen2.5-7B-Instruct-Turbo"],
922
- hostname: "api.together.xyz"
923
- });
924
-
925
- // src/internal/providers/builtin/vertex.ts
926
- var VERTEX = {
927
- name: "vertex",
928
- apiMode: "anthropic_messages",
929
- // sub-dispatched in selectTransport by profile.name
930
- envVars: ["GOOGLE_APPLICATION_CREDENTIALS"],
931
- authType: "gcp_oauth",
932
- baseUrl: "https://us-central1-aiplatform.googleapis.com",
933
- modelsUrl: void 0,
934
- hostname: "aiplatform.googleapis.com",
935
- fallbackModels: [
936
- "vertex/anthropic/claude-sonnet-4-5@20250929",
937
- "vertex/google/gemini-2.0-flash-001"
938
- ]
939
- };
940
-
941
- // src/internal/providers/builtin/xai.ts
942
- var XAI = openAiCompatibleProfile({
943
- name: "xai",
944
- aliases: ["grok"],
945
- baseUrl: "https://api.x.ai/v1",
946
- envVars: ["XAI_API_KEY"],
947
- fallbackModels: ["grok-4.5", "grok-4.3"],
948
- hostname: "api.x.ai"
949
- });
950
-
951
- // src/internal/providers/builtin/index.ts
952
- var _registeredState = (() => {
953
- const g = globalThis;
954
- const sym = /* @__PURE__ */ Symbol.for("theokit-sdk.providers.builtins-registered");
955
- if (g[sym] === void 0) g[sym] = { done: false };
956
- return g[sym];
957
- })();
958
- function registerBuiltins() {
959
- if (_registeredState.done) return;
960
- _registeredState.done = true;
961
- registerProvider(ANTHROPIC);
962
- registerProvider(OPENAI);
963
- registerProvider(OPENAI_CHATGPT);
964
- registerProvider(OPENROUTER);
965
- registerProvider(GEMINI);
966
- registerProvider(OLLAMA);
967
- registerProvider(LMSTUDIO);
968
- registerProvider(LLAMACPP);
969
- registerProvider(BEDROCK);
970
- registerProvider(VERTEX);
971
- registerProvider(GOOGLE);
972
- registerProvider(MISTRAL);
973
- registerProvider(GROQ);
974
- registerProvider(COHERE);
975
- registerProvider(DEEPINFRA);
976
- registerProvider(TOGETHER);
977
- registerProvider(XAI);
978
- registerProvider(PERPLEXITY);
979
- registerProvider(CEREBRAS);
980
- registerCatalogProviders();
981
- }
982
-
983
- // src/internal/providers/catalog-source-models-dev.ts
984
88
  var DEFAULT_URL = "https://models.dev/api.json";
985
89
  var TTL_MS = 60 * 60 * 1e3;
986
90
  var FETCH_TIMEOUT_MS = 1e4;
@@ -1155,6 +259,6 @@ function getModelInfo(modelId) {
1155
259
  return getCatalogModelInfo(modelId);
1156
260
  }
1157
261
 
1158
- export { getModelInfo, humanizeModelName, parseModelId, refreshModelCatalog, resolveModelCapabilities, toModelOption };
262
+ export { getModelInfo, humanizeModelName, refreshModelCatalog, resolveModelCapabilities, toModelOption };
1159
263
  //# sourceMappingURL=models.js.map
1160
264
  //# sourceMappingURL=models.js.map