@nyte-ai/ai 0.0.0-stage → 0.0.19

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 (314) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +170 -2
  3. package/THIRD-PARTY-NOTICES.md +866 -0
  4. package/dist/chunks/account-limits-cache-031vfpt3.js +37 -0
  5. package/dist/chunks/account-limits-cache-09vs98g6.js +41 -0
  6. package/dist/chunks/account-limits-cache-0af5gqeg.js +15 -0
  7. package/dist/chunks/account-limits-cache-0yd6bde8.js +103 -0
  8. package/dist/chunks/account-limits-cache-1jv43fhh.js +22 -0
  9. package/dist/chunks/account-limits-cache-3ykqmnj5.js +88 -0
  10. package/dist/chunks/account-limits-cache-4b8ckwqw.js +293 -0
  11. package/dist/chunks/account-limits-cache-4fn5w63p.js +295 -0
  12. package/dist/chunks/account-limits-cache-4hptgd2h.js +49 -0
  13. package/dist/chunks/account-limits-cache-53e64mhx.js +417 -0
  14. package/dist/chunks/account-limits-cache-5jdhn0e1.js +562 -0
  15. package/dist/chunks/account-limits-cache-5rx2pfm5.js +8 -0
  16. package/dist/chunks/account-limits-cache-5ygxyyss.js +19 -0
  17. package/dist/chunks/account-limits-cache-6250ykn6.js +21 -0
  18. package/dist/chunks/account-limits-cache-6x05n06z.js +49 -0
  19. package/dist/chunks/account-limits-cache-736tdyme.js +6 -0
  20. package/dist/chunks/account-limits-cache-75smws02.js +213 -0
  21. package/dist/chunks/account-limits-cache-7z9s8j16.js +139 -0
  22. package/dist/chunks/account-limits-cache-8137j3zp.js +37 -0
  23. package/dist/chunks/account-limits-cache-8qzk56vj.js +160 -0
  24. package/dist/chunks/account-limits-cache-8s8bz4dr.js +36 -0
  25. package/dist/chunks/account-limits-cache-8vzx8k6r.js +166 -0
  26. package/dist/chunks/account-limits-cache-8wfqg73s.js +135 -0
  27. package/dist/chunks/account-limits-cache-90c9c2eb.js +50 -0
  28. package/dist/chunks/account-limits-cache-9wqk28n5.js +25 -0
  29. package/dist/chunks/account-limits-cache-a1jyaq00.js +56 -0
  30. package/dist/chunks/account-limits-cache-a558rjbg.js +138 -0
  31. package/dist/chunks/account-limits-cache-a55e14fr.js +70 -0
  32. package/dist/chunks/account-limits-cache-a6cgeagz.js +77 -0
  33. package/dist/chunks/account-limits-cache-ag5b8dja.js +38 -0
  34. package/dist/chunks/account-limits-cache-b0x2sfya.js +45 -0
  35. package/dist/chunks/account-limits-cache-b23sbrke.js +26 -0
  36. package/dist/chunks/account-limits-cache-b4edaybk.js +8 -0
  37. package/dist/chunks/account-limits-cache-bsknrh6t.js +74 -0
  38. package/dist/chunks/account-limits-cache-csbxvam7.js +12 -0
  39. package/dist/chunks/account-limits-cache-cw7q7vfy.js +293 -0
  40. package/dist/chunks/account-limits-cache-d1ypzqzp.js +27 -0
  41. package/dist/chunks/account-limits-cache-d2a51dka.js +17 -0
  42. package/dist/chunks/account-limits-cache-dejeygdt.js +114 -0
  43. package/dist/chunks/account-limits-cache-eejm0vth.js +11 -0
  44. package/dist/chunks/account-limits-cache-ehy0ze2b.js +33 -0
  45. package/dist/chunks/account-limits-cache-emg5b4hj.js +53 -0
  46. package/dist/chunks/account-limits-cache-eqwweapz.js +6 -0
  47. package/dist/chunks/account-limits-cache-eyx1jcxc.js +8 -0
  48. package/dist/chunks/account-limits-cache-f9z00x8c.js +36 -0
  49. package/dist/chunks/account-limits-cache-fbkaq46e.js +113 -0
  50. package/dist/chunks/account-limits-cache-fdwad56n.js +399 -0
  51. package/dist/chunks/account-limits-cache-fht68jp2.js +22 -0
  52. package/dist/chunks/account-limits-cache-fp03ztsw.js +17 -0
  53. package/dist/chunks/account-limits-cache-fsktnetm.js +69 -0
  54. package/dist/chunks/account-limits-cache-fvadc36m.js +110 -0
  55. package/dist/chunks/account-limits-cache-gknnm1kv.js +13 -0
  56. package/dist/chunks/account-limits-cache-gqsrbky9.js +40 -0
  57. package/dist/chunks/account-limits-cache-gr671dr2.js +0 -0
  58. package/dist/chunks/account-limits-cache-gs8a3fhw.js +32 -0
  59. package/dist/chunks/account-limits-cache-gsa5tzck.js +37 -0
  60. package/dist/chunks/account-limits-cache-h92bzz1j.js +235 -0
  61. package/dist/chunks/account-limits-cache-hemxtapd.js +142 -0
  62. package/dist/chunks/account-limits-cache-hj1h48sc.js +92 -0
  63. package/dist/chunks/account-limits-cache-hj3ek3ty.js +128 -0
  64. package/dist/chunks/account-limits-cache-hwehc67r.js +509 -0
  65. package/dist/chunks/account-limits-cache-hyzn1jmk.js +46 -0
  66. package/dist/chunks/account-limits-cache-j2bt392s.js +63 -0
  67. package/dist/chunks/account-limits-cache-k0pkzhbx.js +74 -0
  68. package/dist/chunks/account-limits-cache-kjx405q0.js +277 -0
  69. package/dist/chunks/account-limits-cache-ks1sjym9.js +37 -0
  70. package/dist/chunks/account-limits-cache-me1x57bs.js +89 -0
  71. package/dist/chunks/account-limits-cache-n3yk6g5c.js +314 -0
  72. package/dist/chunks/account-limits-cache-nbhht7xz.js +72 -0
  73. package/dist/chunks/account-limits-cache-nbkyhs6v.js +42 -0
  74. package/dist/chunks/account-limits-cache-nn9jebsj.js +26 -0
  75. package/dist/chunks/account-limits-cache-nxkprk3g.js +13 -0
  76. package/dist/chunks/account-limits-cache-nyy770yd.js +38 -0
  77. package/dist/chunks/account-limits-cache-pfa86y8e.js +45 -0
  78. package/dist/chunks/account-limits-cache-pfr14mcn.js +59 -0
  79. package/dist/chunks/account-limits-cache-q1ebtvet.js +8 -0
  80. package/dist/chunks/account-limits-cache-q63mc41j.js +51 -0
  81. package/dist/chunks/account-limits-cache-re8hpzwn.js +104 -0
  82. package/dist/chunks/account-limits-cache-rz8p1g5y.js +9 -0
  83. package/dist/chunks/account-limits-cache-skbfmzqe.js +7 -0
  84. package/dist/chunks/account-limits-cache-tc38g0ca.js +20 -0
  85. package/dist/chunks/account-limits-cache-v4n30az2.js +24 -0
  86. package/dist/chunks/account-limits-cache-vwgfz727.js +281 -0
  87. package/dist/chunks/account-limits-cache-wtg64ez7.js +69 -0
  88. package/dist/chunks/account-limits-cache-x9fvb3s5.js +8 -0
  89. package/dist/chunks/account-limits-cache-xds88kxd.js +209 -0
  90. package/dist/chunks/account-limits-cache-xz65wyd1.js +428 -0
  91. package/dist/chunks/account-limits-cache-ydq8p8qp.js +39 -0
  92. package/dist/chunks/account-limits-cache-ykbqsvv6.js +134 -0
  93. package/dist/chunks/account-limits-cache-yzyp0c2h.js +251 -0
  94. package/dist/chunks/account-limits-cache-za42x8a3.js +25 -0
  95. package/dist/chunks/account-limits-cache-zcbkmrvy.js +79 -0
  96. package/dist/chunks/account-limits-cache-zgzptd0z.js +62 -0
  97. package/dist/chunks/account-limits-cache-zn01kscn.js +252 -0
  98. package/dist/chunks/account-limits-cache-zpjmeyt0.js +113 -0
  99. package/dist/chunks/account-limits-cache-zqdb4yh4.js +8 -0
  100. package/dist/src/account-limits-cache.d.ts +16 -0
  101. package/dist/src/account-limits-cache.js +7 -0
  102. package/dist/src/api/anthropic-client.d.ts +25 -0
  103. package/dist/src/api/anthropic-client.js +30 -0
  104. package/dist/src/api/anthropic-convert.d.ts +17 -0
  105. package/dist/src/api/anthropic-convert.js +14 -0
  106. package/dist/src/api/anthropic-events.d.ts +101 -0
  107. package/dist/src/api/anthropic-events.js +11 -0
  108. package/dist/src/api/anthropic-messages.d.ts +88 -0
  109. package/dist/src/api/anthropic-messages.js +578 -0
  110. package/dist/src/api/anthropic-messages.lazy.d.ts +2 -0
  111. package/dist/src/api/anthropic-messages.lazy.js +11 -0
  112. package/dist/src/api/assistant-stream.d.ts +23 -0
  113. package/dist/src/api/assistant-stream.js +15 -0
  114. package/dist/src/api/claude-code.d.ts +12 -0
  115. package/dist/src/api/claude-code.js +12 -0
  116. package/dist/src/api/cloudflare.d.ts +8 -0
  117. package/dist/src/api/cloudflare.js +11 -0
  118. package/dist/src/api/constrained-sampling.d.ts +24 -0
  119. package/dist/src/api/constrained-sampling.js +16 -0
  120. package/dist/src/api/deferred.d.ts +7 -0
  121. package/dist/src/api/deferred.js +10 -0
  122. package/dist/src/api/github-copilot-headers.d.ts +15 -0
  123. package/dist/src/api/github-copilot-headers.js +12 -0
  124. package/dist/src/api/google-generative-ai.d.ts +22 -0
  125. package/dist/src/api/google-generative-ai.js +583 -0
  126. package/dist/src/api/google-generative-ai.lazy.d.ts +2 -0
  127. package/dist/src/api/google-generative-ai.lazy.js +11 -0
  128. package/dist/src/api/lazy.d.ts +18 -0
  129. package/dist/src/api/lazy.js +12 -0
  130. package/dist/src/api/openai-codex-compact.d.ts +14 -0
  131. package/dist/src/api/openai-codex-compact.js +389 -0
  132. package/dist/src/api/openai-codex-compaction-error.d.ts +7 -0
  133. package/dist/src/api/openai-codex-compaction-error.js +6 -0
  134. package/dist/src/api/openai-codex-protocol.d.ts +125 -0
  135. package/dist/src/api/openai-codex-protocol.js +48 -0
  136. package/dist/src/api/openai-codex-responses.d.ts +4 -0
  137. package/dist/src/api/openai-codex-responses.js +175 -0
  138. package/dist/src/api/openai-codex-responses.lazy.d.ts +2 -0
  139. package/dist/src/api/openai-codex-responses.lazy.js +11 -0
  140. package/dist/src/api/openai-codex-websocket.d.ts +13 -0
  141. package/dist/src/api/openai-codex-websocket.js +37 -0
  142. package/dist/src/api/openai-codex-wire.d.ts +44 -0
  143. package/dist/src/api/openai-codex-wire.js +34 -0
  144. package/dist/src/api/openai-compact.d.ts +9 -0
  145. package/dist/src/api/openai-compact.js +12 -0
  146. package/dist/src/api/openai-completions-convert.d.ts +58 -0
  147. package/dist/src/api/openai-completions-convert.js +21 -0
  148. package/dist/src/api/openai-completions-params.d.ts +29 -0
  149. package/dist/src/api/openai-completions-params.js +20 -0
  150. package/dist/src/api/openai-completions-reasoning.d.ts +54 -0
  151. package/dist/src/api/openai-completions-reasoning.js +22 -0
  152. package/dist/src/api/openai-completions.d.ts +22 -0
  153. package/dist/src/api/openai-completions.js +484 -0
  154. package/dist/src/api/openai-completions.lazy.d.ts +5 -0
  155. package/dist/src/api/openai-completions.lazy.js +11 -0
  156. package/dist/src/api/openai-prompt-cache.d.ts +1 -0
  157. package/dist/src/api/openai-prompt-cache.js +6 -0
  158. package/dist/src/api/openai-responses-convert.d.ts +58 -0
  159. package/dist/src/api/openai-responses-convert.js +16 -0
  160. package/dist/src/api/openai-responses-events.d.ts +379 -0
  161. package/dist/src/api/openai-responses-events.js +12 -0
  162. package/dist/src/api/openai-responses-stream.d.ts +36 -0
  163. package/dist/src/api/openai-responses-stream.js +25 -0
  164. package/dist/src/api/openai-responses.d.ts +18 -0
  165. package/dist/src/api/openai-responses.js +276 -0
  166. package/dist/src/api/openai-responses.lazy.d.ts +2 -0
  167. package/dist/src/api/openai-responses.lazy.js +11 -0
  168. package/dist/src/api/simple-options.d.ts +17 -0
  169. package/dist/src/api/simple-options.js +18 -0
  170. package/dist/src/api/token-count.d.ts +5 -0
  171. package/dist/src/api/token-count.js +8 -0
  172. package/dist/src/api/transform-messages.d.ts +9 -0
  173. package/dist/src/api/transform-messages.js +6 -0
  174. package/dist/src/api-options.d.ts +27 -0
  175. package/dist/src/api-options.js +0 -0
  176. package/dist/src/auth/context.d.ts +11 -0
  177. package/dist/src/auth/context.js +6 -0
  178. package/dist/src/auth/credential-store.d.ts +17 -0
  179. package/dist/src/auth/credential-store.js +7 -0
  180. package/dist/src/auth/helpers.d.ts +24 -0
  181. package/dist/src/auth/helpers.js +8 -0
  182. package/dist/src/auth/oauth/anthropic.d.ts +7 -0
  183. package/dist/src/auth/oauth/anthropic.js +12 -0
  184. package/dist/src/auth/oauth/authorization-input.d.ts +14 -0
  185. package/dist/src/auth/oauth/authorization-input.js +6 -0
  186. package/dist/src/auth/oauth/device-code.d.ts +29 -0
  187. package/dist/src/auth/oauth/device-code.js +9 -0
  188. package/dist/src/auth/oauth/github-copilot.d.ts +23 -0
  189. package/dist/src/auth/oauth/github-copilot.js +12 -0
  190. package/dist/src/auth/oauth/load.d.ts +14 -0
  191. package/dist/src/auth/oauth/load.js +10 -0
  192. package/dist/src/auth/oauth/oauth-page.d.ts +13 -0
  193. package/dist/src/auth/oauth/oauth-page.js +8 -0
  194. package/dist/src/auth/oauth/openai-codex.d.ts +10 -0
  195. package/dist/src/auth/oauth/openai-codex.js +18 -0
  196. package/dist/src/auth/oauth/pkce.d.ts +12 -0
  197. package/dist/src/auth/oauth/pkce.js +6 -0
  198. package/dist/src/auth/resolve.d.ts +38 -0
  199. package/dist/src/auth/resolve.js +12 -0
  200. package/dist/src/auth/store.d.ts +29 -0
  201. package/dist/src/auth/store.js +10 -0
  202. package/dist/src/auth/types.d.ts +291 -0
  203. package/dist/src/auth/types.js +8 -0
  204. package/dist/src/auth/verify.d.ts +13 -0
  205. package/dist/src/auth/verify.js +7 -0
  206. package/dist/src/bun-oauth.d.ts +2 -0
  207. package/dist/src/bun-oauth.js +25 -0
  208. package/dist/src/env-api-keys.d.ts +32 -0
  209. package/dist/src/env-api-keys.js +27 -0
  210. package/dist/src/file-models-store.d.ts +18 -0
  211. package/dist/src/file-models-store.js +9 -0
  212. package/dist/src/index.d.ts +62 -0
  213. package/dist/src/index.js +372 -0
  214. package/dist/src/model-capabilities.d.ts +21 -0
  215. package/dist/src/model-capabilities.js +14 -0
  216. package/dist/src/model-pricing.d.ts +6 -0
  217. package/dist/src/model-pricing.js +10 -0
  218. package/dist/src/model-variants.d.ts +21 -0
  219. package/dist/src/model-variants.js +19 -0
  220. package/dist/src/models-refresh.d.ts +27 -0
  221. package/dist/src/models-refresh.js +9 -0
  222. package/dist/src/models-store.d.ts +31 -0
  223. package/dist/src/models-store.js +6 -0
  224. package/dist/src/models-types.d.ts +206 -0
  225. package/dist/src/models-types.js +0 -0
  226. package/dist/src/models.d.ts +7 -0
  227. package/dist/src/models.js +44 -0
  228. package/dist/src/prompt-cache.d.ts +5 -0
  229. package/dist/src/prompt-cache.js +9 -0
  230. package/dist/src/provider.d.ts +23 -0
  231. package/dist/src/provider.js +14 -0
  232. package/dist/src/providers/account-limits.d.ts +13 -0
  233. package/dist/src/providers/account-limits.js +8 -0
  234. package/dist/src/providers/anthropic-limits.d.ts +9 -0
  235. package/dist/src/providers/anthropic-limits.js +10 -0
  236. package/dist/src/providers/anthropic.d.ts +2 -0
  237. package/dist/src/providers/anthropic.js +25 -0
  238. package/dist/src/providers/github-copilot-catalog.d.ts +5 -0
  239. package/dist/src/providers/github-copilot-catalog.js +7 -0
  240. package/dist/src/providers/github-copilot.d.ts +2 -0
  241. package/dist/src/providers/github-copilot.js +23 -0
  242. package/dist/src/providers/nyte-catalog.d.ts +15 -0
  243. package/dist/src/providers/nyte-catalog.js +63 -0
  244. package/dist/src/providers/openai-codex-limits.d.ts +8 -0
  245. package/dist/src/providers/openai-codex-limits.js +14 -0
  246. package/dist/src/providers/openai-codex.d.ts +2 -0
  247. package/dist/src/providers/openai-codex.js +23 -0
  248. package/dist/src/providers/openai.d.ts +2 -0
  249. package/dist/src/providers/openai.js +19 -0
  250. package/dist/src/providers/opencode-go.d.ts +5 -0
  251. package/dist/src/providers/opencode-go.js +22 -0
  252. package/dist/src/providers/opencode-headers.d.ts +5 -0
  253. package/dist/src/providers/opencode-headers.js +6 -0
  254. package/dist/src/providers/opencode.d.ts +14 -0
  255. package/dist/src/providers/opencode.js +23 -0
  256. package/dist/src/providers/openrouter.d.ts +2 -0
  257. package/dist/src/providers/openrouter.js +19 -0
  258. package/dist/src/providers/vercel-ai-gateway.d.ts +3 -0
  259. package/dist/src/providers/vercel-ai-gateway.js +19 -0
  260. package/dist/src/session-resources.d.ts +9 -0
  261. package/dist/src/session-resources.js +10 -0
  262. package/dist/src/types.d.ts +210 -0
  263. package/dist/src/types.js +1 -0
  264. package/dist/src/utils/abort.d.ts +12 -0
  265. package/dist/src/utils/abort.js +10 -0
  266. package/dist/src/utils/deferred-tools.d.ts +11 -0
  267. package/dist/src/utils/deferred-tools.js +6 -0
  268. package/dist/src/utils/diagnostics.d.ts +11 -0
  269. package/dist/src/utils/diagnostics.js +12 -0
  270. package/dist/src/utils/error-body.d.ts +26 -0
  271. package/dist/src/utils/error-body.js +10 -0
  272. package/dist/src/utils/estimate.d.ts +20 -0
  273. package/dist/src/utils/estimate.js +14 -0
  274. package/dist/src/utils/event-stream.d.ts +22 -0
  275. package/dist/src/utils/event-stream.js +11 -0
  276. package/dist/src/utils/failure.d.ts +49 -0
  277. package/dist/src/utils/failure.js +10 -0
  278. package/dist/src/utils/fifo-queue.d.ts +11 -0
  279. package/dist/src/utils/fifo-queue.js +6 -0
  280. package/dist/src/utils/hash.d.ts +5 -0
  281. package/dist/src/utils/hash.js +6 -0
  282. package/dist/src/utils/headers.d.ts +12 -0
  283. package/dist/src/utils/headers.js +14 -0
  284. package/dist/src/utils/json-parse.d.ts +33 -0
  285. package/dist/src/utils/json-parse.js +12 -0
  286. package/dist/src/utils/node-http-proxy.d.ts +6 -0
  287. package/dist/src/utils/node-http-proxy.js +9 -0
  288. package/dist/src/utils/nyte-home.d.ts +2 -0
  289. package/dist/src/utils/nyte-home.js +6 -0
  290. package/dist/src/utils/nyte-user-agent.d.ts +1 -0
  291. package/dist/src/utils/nyte-user-agent.js +6 -0
  292. package/dist/src/utils/overflow.d.ts +18 -0
  293. package/dist/src/utils/overflow.js +9 -0
  294. package/dist/src/utils/provider-env.d.ts +9 -0
  295. package/dist/src/utils/provider-env.js +6 -0
  296. package/dist/src/utils/provider-retry.d.ts +22 -0
  297. package/dist/src/utils/provider-retry.js +9 -0
  298. package/dist/src/utils/retry.d.ts +66 -0
  299. package/dist/src/utils/retry.js +18 -0
  300. package/dist/src/utils/sanitize-unicode.d.ts +24 -0
  301. package/dist/src/utils/sanitize-unicode.js +6 -0
  302. package/dist/src/utils/sse.d.ts +21 -0
  303. package/dist/src/utils/sse.js +6 -0
  304. package/dist/src/utils/text.d.ts +5 -0
  305. package/dist/src/utils/text.js +10 -0
  306. package/dist/src/utils/transcript.d.ts +5 -0
  307. package/dist/src/utils/transcript.js +36 -0
  308. package/dist/src/utils/typebox-helpers.d.ts +19 -0
  309. package/dist/src/utils/typebox-helpers.js +6 -0
  310. package/dist/src/utils/uuid.d.ts +2 -0
  311. package/dist/src/utils/uuid.js +6 -0
  312. package/dist/src/utils/validation.d.ts +13 -0
  313. package/dist/src/utils/validation.js +8 -0
  314. package/package.json +152 -3
@@ -0,0 +1,134 @@
1
+ import {
2
+ lazyStream2
3
+ } from "./account-limits-cache-90c9c2eb.js";
4
+ import {
5
+ ModelsError2
6
+ } from "./account-limits-cache-7z9s8j16.js";
7
+
8
+ // src/provider.ts
9
+ import { ModelSchema } from "@nyte-ai/schema/model";
10
+ import { Value } from "typebox/value";
11
+ var CATALOG_FRESHNESS_WINDOW_MS = 4 * 60 * 60 * 1000;
12
+ function createProvider2(input) {
13
+ let catalogModels = [];
14
+ const api = input.api;
15
+ const single = "streamSimple" in api ? api : undefined;
16
+ const byApi = new Map("streamSimple" in api ? [] : Object.entries(api));
17
+ const apiFor = (model) => single ?? byApi.get(model.api);
18
+ const usableModels = (catalog) => catalog.filter((model) => Value.Check(ModelSchema, model) && model.provider === input.id && apiFor(model) !== undefined);
19
+ const dispatch = (model, run) => {
20
+ const streams = apiFor(model);
21
+ if (!streams) {
22
+ return lazyStream2(model, async () => {
23
+ throw new ModelsError2("stream", `Provider ${input.id} has no API implementation for "${model.api}"`);
24
+ });
25
+ }
26
+ return run(streams);
27
+ };
28
+ const provider = {
29
+ id: input.id,
30
+ name: input.name ?? input.id,
31
+ baseUrl: input.baseUrl,
32
+ headers: input.headers,
33
+ promptCache: input.promptCache,
34
+ auth: input.auth,
35
+ fetchAccountLimits: input.fetchAccountLimits,
36
+ getModels: () => catalogModels,
37
+ refreshModels: async (context) => {
38
+ if (context.stored) {
39
+ const restored = usableModels(context.stored.models);
40
+ if (!await context.publish({
41
+ update: () => {
42
+ catalogModels = restored;
43
+ }
44
+ })) {
45
+ return;
46
+ }
47
+ }
48
+ if (!context.allowNetwork || context.signal.aborted)
49
+ return;
50
+ if (context.force !== true && context.stored?.checkedAt !== undefined && Date.now() - context.stored.checkedAt < CATALOG_FRESHNESS_WINDOW_MS) {
51
+ return;
52
+ }
53
+ const headers = new Headers({ Accept: "application/json" });
54
+ if (context.stored?.etag !== undefined) {
55
+ headers.set("If-None-Match", context.stored.etag);
56
+ }
57
+ let response;
58
+ try {
59
+ response = await context.catalog.fetch(`${context.catalog.url.replace(/\/+$/u, "")}/${input.id}.json`, {
60
+ headers,
61
+ signal: context.signal,
62
+ redirect: "error"
63
+ });
64
+ } catch (error) {
65
+ context.signal.throwIfAborted();
66
+ throw new ModelsError2("model_source", `Model catalog request failed for ${input.id}`, {
67
+ cause: error
68
+ });
69
+ }
70
+ const checkedAt = Date.now();
71
+ if (response.status === 304) {
72
+ if (!context.stored) {
73
+ throw new ModelsError2("model_source", `Model catalog request failed for ${input.id} (HTTP 304 without cached models)`);
74
+ }
75
+ await context.publish({ persist: { ...context.stored, checkedAt } });
76
+ return;
77
+ }
78
+ if (response.status !== 200) {
79
+ throw new ModelsError2("model_source", `Model catalog request failed for ${input.id} (HTTP ${String(response.status)})`);
80
+ }
81
+ let value;
82
+ try {
83
+ value = await response.json();
84
+ } catch {
85
+ throw new ModelsError2("model_source", `Model catalog request failed for ${input.id} (HTTP 200, invalid JSON)`);
86
+ }
87
+ if (!Array.isArray(value)) {
88
+ throw new ModelsError2("model_source", `Model catalog request failed for ${input.id} (HTTP 200, expected an array)`);
89
+ }
90
+ const refreshed = usableModels(value);
91
+ const lastModifiedHeader = response.headers.get("Last-Modified");
92
+ const parsedLastModified = lastModifiedHeader === null ? undefined : Date.parse(lastModifiedHeader);
93
+ const lastModified = parsedLastModified === undefined || Number.isNaN(parsedLastModified) ? undefined : parsedLastModified;
94
+ if (context.signal.aborted)
95
+ return;
96
+ await context.publish({
97
+ persist: {
98
+ models: value,
99
+ etag: response.headers.get("ETag") ?? undefined,
100
+ lastModified,
101
+ checkedAt
102
+ },
103
+ update: () => {
104
+ catalogModels = refreshed;
105
+ }
106
+ });
107
+ },
108
+ filterModels: input.filterModels,
109
+ stream: (model, context, options) => dispatch(model, (streams) => streams.stream(model, context, options)),
110
+ streamSimple: (model, context, options) => dispatch(model, (streams) => streams.streamSimple(model, context, options))
111
+ };
112
+ const streams = single ? [single] : [...byApi.values()].filter((entry) => entry !== undefined);
113
+ if (streams.some((entry) => entry.fetchDeferred !== undefined)) {
114
+ provider.fetchDeferred = (model, handle, options) => lazyStream2(model, async () => {
115
+ const implementation = apiFor(model);
116
+ if (!implementation?.fetchDeferred) {
117
+ throw new ModelsError2("provider", `Provider ${input.id} does not support deferred responses for "${model.api}"`);
118
+ }
119
+ return implementation.fetchDeferred(model, handle, options);
120
+ });
121
+ }
122
+ if (streams.some((entry) => entry.cancelDeferred !== undefined)) {
123
+ provider.cancelDeferred = async (model, handle, options) => {
124
+ const implementation = apiFor(model);
125
+ if (!implementation?.cancelDeferred) {
126
+ throw new ModelsError2("provider", `Provider ${input.id} cannot cancel deferred responses for "${model.api}"`);
127
+ }
128
+ await implementation.cancelDeferred(model, handle, options);
129
+ };
130
+ }
131
+ return provider;
132
+ }
133
+
134
+ export { createProvider2 };
@@ -0,0 +1,251 @@
1
+ import {
2
+ defaultNyteHome2
3
+ } from "./account-limits-cache-rz8p1g5y.js";
4
+ import {
5
+ readCredentialAccounts2
6
+ } from "./account-limits-cache-b0x2sfya.js";
7
+
8
+ // src/auth/store.ts
9
+ import { randomUUID } from "node:crypto";
10
+ import {
11
+ closeSync,
12
+ existsSync,
13
+ mkdirSync,
14
+ openSync,
15
+ readFileSync,
16
+ renameSync,
17
+ rmSync,
18
+ statSync,
19
+ writeFileSync,
20
+ writeSync
21
+ } from "node:fs";
22
+ import { hostname } from "node:os";
23
+ import { dirname, join } from "node:path";
24
+ import process from "node:process";
25
+ import { Type } from "typebox";
26
+ import { Value } from "typebox/value";
27
+ function defaultAuthPath2() {
28
+ return join(defaultNyteHome2(), "auth.json");
29
+ }
30
+ var LOCK_TIMEOUT_MS = 30000;
31
+ var LOCK_RETRY_MS = 25;
32
+ var LOCK_ABANDONED_MS = 2 * LOCK_TIMEOUT_MS;
33
+ var RECOVERY_STALE_MS = 1000;
34
+ var CredentialFileSchema = Type.Record(Type.String(), Type.Unknown());
35
+ var SystemErrorSchema = Type.Object({ code: Type.String() });
36
+ function errorCode(cause) {
37
+ return Value.Check(SystemErrorSchema, cause) ? cause.code : undefined;
38
+ }
39
+ function lockOwner() {
40
+ return `${process.pid} ${hostname()} ${randomUUID()}`;
41
+ }
42
+ function readOwner(lockPath) {
43
+ try {
44
+ return readFileSync(lockPath, "utf8");
45
+ } catch {
46
+ return;
47
+ }
48
+ }
49
+ function localOwnerPid(owner) {
50
+ if (owner === undefined)
51
+ return;
52
+ const [pid, host] = owner.split(" ");
53
+ if (host !== hostname())
54
+ return;
55
+ const parsed = Number(pid);
56
+ return Number.isSafeInteger(parsed) && parsed > 0 ? parsed : undefined;
57
+ }
58
+ function processAlive(pid) {
59
+ try {
60
+ process.kill(pid, 0);
61
+ return true;
62
+ } catch (error) {
63
+ return errorCode(error) === "EPERM";
64
+ }
65
+ }
66
+ function ageMs(path) {
67
+ try {
68
+ return Date.now() - statSync(path).mtimeMs;
69
+ } catch {
70
+ return;
71
+ }
72
+ }
73
+ function lockAbandoned(lockPath) {
74
+ const pid = localOwnerPid(readOwner(lockPath));
75
+ if (pid !== undefined && !processAlive(pid))
76
+ return true;
77
+ const age = ageMs(lockPath);
78
+ return age !== undefined && age > LOCK_ABANDONED_MS;
79
+ }
80
+ function createLock(lockPath, owner) {
81
+ let handle;
82
+ try {
83
+ handle = openSync(lockPath, "wx", 384);
84
+ } catch (error) {
85
+ if (errorCode(error) === "EEXIST")
86
+ return false;
87
+ throw error;
88
+ }
89
+ try {
90
+ writeSync(handle, owner);
91
+ } finally {
92
+ closeSync(handle);
93
+ }
94
+ return true;
95
+ }
96
+ function reclaimAbandonedLock(lockPath, owner) {
97
+ const recoveryPath = `${lockPath}.recovery`;
98
+ if (!createLock(recoveryPath, owner)) {
99
+ const age = ageMs(recoveryPath);
100
+ if (age !== undefined && age > RECOVERY_STALE_MS)
101
+ rmSync(recoveryPath, { force: true });
102
+ return;
103
+ }
104
+ try {
105
+ if (lockAbandoned(lockPath))
106
+ rmSync(lockPath, { force: true });
107
+ } finally {
108
+ rmSync(recoveryPath, { force: true });
109
+ }
110
+ }
111
+ async function acquireLock(lockPath, signal) {
112
+ const owner = lockOwner();
113
+ const lock = {
114
+ held: () => readOwner(lockPath) === owner,
115
+ release: () => {
116
+ if (readOwner(lockPath) !== owner)
117
+ return;
118
+ try {
119
+ rmSync(lockPath, { force: true });
120
+ } catch {
121
+ return;
122
+ }
123
+ }
124
+ };
125
+ const deadline = Date.now() + LOCK_TIMEOUT_MS;
126
+ for (;; ) {
127
+ signal?.throwIfAborted();
128
+ if (createLock(lockPath, owner))
129
+ return lock;
130
+ if (Date.now() >= deadline) {
131
+ throw new Error(`Timed out waiting for the credential lock at ${lockPath}`);
132
+ }
133
+ if (lockAbandoned(lockPath))
134
+ reclaimAbandonedLock(lockPath, owner);
135
+ await new Promise((resolve) => {
136
+ setTimeout(resolve, LOCK_RETRY_MS);
137
+ });
138
+ }
139
+ }
140
+ async function publish(staging, path) {
141
+ const deadline = Date.now() + LOCK_TIMEOUT_MS;
142
+ for (;; ) {
143
+ try {
144
+ renameSync(staging, path);
145
+ return;
146
+ } catch (error) {
147
+ const busy = process.platform === "win32" && error instanceof Error && "code" in error && (error.code === "EPERM" || error.code === "EACCES" || error.code === "EBUSY");
148
+ if (!busy || Date.now() >= deadline)
149
+ throw error;
150
+ }
151
+ await new Promise((resolve) => {
152
+ setTimeout(resolve, LOCK_RETRY_MS);
153
+ });
154
+ }
155
+ }
156
+
157
+ class FileCredentialStore2 {
158
+ path;
159
+ lockPath;
160
+ constructor(path = defaultAuthPath2()) {
161
+ this.path = path;
162
+ this.lockPath = `${path}.lock`;
163
+ }
164
+ load() {
165
+ if (!existsSync(this.path))
166
+ return {};
167
+ const text = readFileSync(this.path, "utf8");
168
+ let parsed;
169
+ try {
170
+ parsed = JSON.parse(text);
171
+ } catch (error) {
172
+ throw new Error(`${this.path} is not valid JSON. Fix or remove it, then sign in again.`, {
173
+ cause: error
174
+ });
175
+ }
176
+ if (!Value.Check(CredentialFileSchema, parsed)) {
177
+ throw new Error(`${this.path} does not hold credentials keyed by provider`);
178
+ }
179
+ return parsed;
180
+ }
181
+ async save(lock, entries) {
182
+ if (!lock.held()) {
183
+ throw new Error(`Another process took over ${this.lockPath}; nothing was written`);
184
+ }
185
+ const staging = `${this.path}.${process.pid}.tmp`;
186
+ try {
187
+ writeFileSync(staging, `${JSON.stringify(entries, null, 2)}
188
+ `, { mode: 384 });
189
+ await publish(staging, this.path);
190
+ } catch (error) {
191
+ rmSync(staging, { force: true });
192
+ throw error;
193
+ }
194
+ }
195
+ async withLock(run, options) {
196
+ options?.signal?.throwIfAborted();
197
+ mkdirSync(dirname(this.path), { recursive: true, mode: 448 });
198
+ const lock = await acquireLock(this.lockPath, options?.signal);
199
+ try {
200
+ return await run(lock);
201
+ } finally {
202
+ lock.release();
203
+ }
204
+ }
205
+ async read(providerId, options) {
206
+ options?.signal?.throwIfAborted();
207
+ return readCredentialAccounts2(this.load()[providerId]);
208
+ }
209
+ async list(options) {
210
+ options?.signal?.throwIfAborted();
211
+ const stored = [];
212
+ for (const [providerId, value] of Object.entries(this.load())) {
213
+ const accounts = readCredentialAccounts2(value);
214
+ if (accounts)
215
+ stored.push(...accounts.accounts.map((account) => ({
216
+ providerId,
217
+ id: account.id,
218
+ label: account.label,
219
+ type: account.credential.type,
220
+ active: account.id === accounts.active
221
+ })));
222
+ }
223
+ return stored;
224
+ }
225
+ modify(providerId, fn, options) {
226
+ return this.withLock(async (lock) => {
227
+ const entries = this.load();
228
+ const current = readCredentialAccounts2(entries[providerId]);
229
+ const next = await fn(current);
230
+ if (next !== undefined) {
231
+ if (next.accounts.length === 0)
232
+ delete entries[providerId];
233
+ else
234
+ entries[providerId] = next;
235
+ await this.save(lock, entries);
236
+ }
237
+ return next ?? current;
238
+ }, options);
239
+ }
240
+ delete(providerId, options) {
241
+ return this.withLock(async (lock) => {
242
+ const entries = this.load();
243
+ if (providerId in entries) {
244
+ delete entries[providerId];
245
+ await this.save(lock, entries);
246
+ }
247
+ }, options);
248
+ }
249
+ }
250
+
251
+ export { defaultAuthPath2, FileCredentialStore2 };
@@ -0,0 +1,25 @@
1
+ // src/api/github-copilot-headers.ts
2
+ var GITHUB_COPILOT_API_VERSION2 = "2026-06-01";
3
+ var GITHUB_COPILOT_DEFAULT_ORIGIN2 = "https://api.individual.githubcopilot.com";
4
+ var GITHUB_COPILOT_HEADERS2 = {
5
+ "User-Agent": "GitHubCopilotChat/0.35.0",
6
+ "Editor-Version": "vscode/1.107.0",
7
+ "Editor-Plugin-Version": "copilot-chat/0.35.0",
8
+ "Copilot-Integration-Id": "vscode-chat"
9
+ };
10
+ function buildCopilotDynamicHeaders2(input) {
11
+ const last = input.messages.at(-1);
12
+ const headers = {
13
+ "X-GitHub-Api-Version": GITHUB_COPILOT_API_VERSION2,
14
+ "X-Initiator": last && last.role !== "user" ? "agent" : "user",
15
+ "Openai-Intent": "conversation-edits",
16
+ "X-Interaction-Type": "conversation-agent"
17
+ };
18
+ if (input.sessionId)
19
+ headers["X-Interaction-Id"] = input.sessionId;
20
+ if (input.messages.some((message) => (message.role === "user" || message.role === "toolResult") && Array.isArray(message.content) && message.content.some((part) => part.type === "image")))
21
+ headers["Copilot-Vision-Request"] = "true";
22
+ return headers;
23
+ }
24
+
25
+ export { GITHUB_COPILOT_API_VERSION2, GITHUB_COPILOT_DEFAULT_ORIGIN2, GITHUB_COPILOT_HEADERS2, buildCopilotDynamicHeaders2 };
@@ -0,0 +1,79 @@
1
+ // src/utils/error-body.ts
2
+ var MAX_PROVIDER_ERROR_BODY_CHARS2 = 4000;
3
+ function normalizeProviderError2(cause) {
4
+ if (!(cause instanceof Error)) {
5
+ return { message: safeJsonStringify(cause), messageCarriesBody: false };
6
+ }
7
+ const status = extractStatus(cause);
8
+ const body = extractBody(cause);
9
+ const messageCarriesBody = body === undefined || cause.message.includes(body);
10
+ return {
11
+ status,
12
+ body,
13
+ message: cause.message,
14
+ messageCarriesBody
15
+ };
16
+ }
17
+ function extractStatus(error) {
18
+ if (typeof error.statusCode === "number")
19
+ return error.statusCode;
20
+ if (typeof error.status === "number")
21
+ return error.status;
22
+ if (typeof error.$metadata?.httpStatusCode === "number")
23
+ return error.$metadata.httpStatusCode;
24
+ if (typeof error.$response?.statusCode === "number")
25
+ return error.$response.statusCode;
26
+ return;
27
+ }
28
+ function extractBody(error) {
29
+ const bodyText = pickBodyText(error);
30
+ if (bodyText === undefined)
31
+ return;
32
+ const trimmed = bodyText.trim();
33
+ if (trimmed.length === 0)
34
+ return;
35
+ return truncateErrorText(trimmed, MAX_PROVIDER_ERROR_BODY_CHARS2);
36
+ }
37
+ function pickBodyText(error) {
38
+ if (typeof error.body === "string")
39
+ return error.body;
40
+ if (plainObjectWithFields(error.error))
41
+ return safeJsonStringify(error.error);
42
+ const responseBody = error.$response?.body;
43
+ if (typeof responseBody === "string")
44
+ return responseBody;
45
+ if (typeof responseBody === "object" && responseBody !== null && "pipe" in responseBody && typeof responseBody.pipe === "function")
46
+ return;
47
+ if (plainObjectWithFields(responseBody))
48
+ return safeJsonStringify(responseBody);
49
+ return;
50
+ }
51
+ function plainObjectWithFields(value) {
52
+ if (typeof value !== "object" || value === null)
53
+ return false;
54
+ const proto = Object.getPrototypeOf(value);
55
+ if (proto !== Object.prototype && proto !== null)
56
+ return false;
57
+ return Object.keys(value).length > 0;
58
+ }
59
+ function formatProviderError2(norm, prefix) {
60
+ if (norm.messageCarriesBody || norm.status === undefined || norm.body === undefined) {
61
+ return prefix !== undefined && norm.status !== undefined ? `${prefix} (${norm.status}): ${norm.message}` : norm.message;
62
+ }
63
+ return prefix !== undefined ? `${prefix} (${norm.status}): ${norm.body}` : `${norm.status}: ${norm.body}`;
64
+ }
65
+ function truncateErrorText(text, maxChars) {
66
+ if (text.length <= maxChars)
67
+ return text;
68
+ return `${text.slice(0, maxChars)}... [truncated ${text.length - maxChars} chars]`;
69
+ }
70
+ function safeJsonStringify(value) {
71
+ try {
72
+ const serialized = JSON.stringify(value);
73
+ return serialized === undefined ? String(value) : serialized;
74
+ } catch {
75
+ return String(value);
76
+ }
77
+ }
78
+
79
+ export { MAX_PROVIDER_ERROR_BODY_CHARS2, normalizeProviderError2, formatProviderError2 };
@@ -0,0 +1,62 @@
1
+ // src/model-capabilities.ts
2
+ import { MODEL_THINKING_LEVELS } from "@nyte-ai/schema/model";
3
+ function hasApi2(model, api) {
4
+ return model.api === api;
5
+ }
6
+ function calculateCost2(model, usage) {
7
+ const inputTokens = usage.input + usage.cacheRead + usage.cacheWrite;
8
+ let rates = model.cost;
9
+ let matchedThreshold = -1;
10
+ for (const tier of model.cost.tiers ?? []) {
11
+ if (inputTokens > tier.inputTokensAbove && tier.inputTokensAbove > matchedThreshold) {
12
+ rates = tier;
13
+ matchedThreshold = tier.inputTokensAbove;
14
+ }
15
+ }
16
+ const longWrite = usage.cacheWrite1h ?? 0;
17
+ const shortWrite = usage.cacheWrite - longWrite;
18
+ usage.cost.input = rates.input / 1e6 * usage.input;
19
+ usage.cost.output = rates.output / 1e6 * usage.output;
20
+ usage.cost.cacheRead = rates.cacheRead / 1e6 * usage.cacheRead;
21
+ usage.cost.cacheWrite = (rates.cacheWrite * shortWrite + rates.input * 2 * longWrite) / 1e6;
22
+ usage.cost.total = usage.cost.input + usage.cost.output + usage.cost.cacheRead + usage.cost.cacheWrite;
23
+ return usage.cost;
24
+ }
25
+ function getSupportedThinkingLevels2(model) {
26
+ if (!model.reasoning)
27
+ return ["off"];
28
+ return MODEL_THINKING_LEVELS.filter((level) => {
29
+ const mapped = model.thinkingLevelMap?.[level];
30
+ if (mapped === null)
31
+ return false;
32
+ if (level === "xhigh" || level === "max")
33
+ return mapped !== undefined;
34
+ return true;
35
+ });
36
+ }
37
+ function clampThinkingLevel2(model, level) {
38
+ const availableLevels = getSupportedThinkingLevels2(model);
39
+ if (availableLevels.includes(level))
40
+ return level;
41
+ const requestedIndex = MODEL_THINKING_LEVELS.findIndex((candidate) => candidate === level);
42
+ if (requestedIndex === -1)
43
+ return availableLevels[0] ?? "off";
44
+ for (let i = requestedIndex;i < MODEL_THINKING_LEVELS.length; i++) {
45
+ const candidate = MODEL_THINKING_LEVELS[i];
46
+ if (availableLevels.includes(candidate))
47
+ return candidate;
48
+ }
49
+ for (let i = requestedIndex - 1;i >= 0; i--) {
50
+ const candidate = MODEL_THINKING_LEVELS[i];
51
+ if (availableLevels.includes(candidate))
52
+ return candidate;
53
+ }
54
+ return availableLevels[0] ?? "off";
55
+ }
56
+ function modelsAreEqual2(a, b) {
57
+ if (!a || !b)
58
+ return false;
59
+ return a.id === b.id && a.provider === b.provider;
60
+ }
61
+
62
+ export { hasApi2, calculateCost2, getSupportedThinkingLevels2, clampThinkingLevel2, modelsAreEqual2 };