@cyanheads/mcp-ts-core 0.1.0-beta.12

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 (485) hide show
  1. package/CLAUDE.md +583 -0
  2. package/LICENSE +201 -0
  3. package/README.md +287 -0
  4. package/biome.json +103 -0
  5. package/dist/app.d.ts +82 -0
  6. package/dist/app.d.ts.map +1 -0
  7. package/dist/app.js +222 -0
  8. package/dist/app.js.map +1 -0
  9. package/dist/cli/init.d.ts +8 -0
  10. package/dist/cli/init.d.ts.map +1 -0
  11. package/dist/cli/init.js +161 -0
  12. package/dist/cli/init.js.map +1 -0
  13. package/dist/config/index.d.ts +349 -0
  14. package/dist/config/index.d.ts.map +1 -0
  15. package/dist/config/index.js +464 -0
  16. package/dist/config/index.js.map +1 -0
  17. package/dist/context.d.ts +119 -0
  18. package/dist/context.d.ts.map +1 -0
  19. package/dist/context.js +144 -0
  20. package/dist/context.js.map +1 -0
  21. package/dist/index.d.ts +8 -0
  22. package/dist/index.d.ts.map +1 -0
  23. package/dist/index.js +9 -0
  24. package/dist/index.js.map +1 -0
  25. package/dist/mcp-server/prompts/prompt-registration.d.ts +33 -0
  26. package/dist/mcp-server/prompts/prompt-registration.d.ts.map +1 -0
  27. package/dist/mcp-server/prompts/prompt-registration.js +91 -0
  28. package/dist/mcp-server/prompts/prompt-registration.js.map +1 -0
  29. package/dist/mcp-server/prompts/utils/newPromptDefinition.d.ts +49 -0
  30. package/dist/mcp-server/prompts/utils/newPromptDefinition.d.ts.map +1 -0
  31. package/dist/mcp-server/prompts/utils/newPromptDefinition.js +39 -0
  32. package/dist/mcp-server/prompts/utils/newPromptDefinition.js.map +1 -0
  33. package/dist/mcp-server/prompts/utils/promptDefinition.d.ts +37 -0
  34. package/dist/mcp-server/prompts/utils/promptDefinition.d.ts.map +1 -0
  35. package/dist/mcp-server/prompts/utils/promptDefinition.js +2 -0
  36. package/dist/mcp-server/prompts/utils/promptDefinition.js.map +1 -0
  37. package/dist/mcp-server/resources/resource-registration.d.ts +27 -0
  38. package/dist/mcp-server/resources/resource-registration.d.ts.map +1 -0
  39. package/dist/mcp-server/resources/resource-registration.js +85 -0
  40. package/dist/mcp-server/resources/resource-registration.js.map +1 -0
  41. package/dist/mcp-server/resources/utils/newResourceDefinition.d.ts +84 -0
  42. package/dist/mcp-server/resources/utils/newResourceDefinition.d.ts.map +1 -0
  43. package/dist/mcp-server/resources/utils/newResourceDefinition.js +40 -0
  44. package/dist/mcp-server/resources/utils/newResourceDefinition.js.map +1 -0
  45. package/dist/mcp-server/resources/utils/newResourceHandlerFactory.d.ts +32 -0
  46. package/dist/mcp-server/resources/utils/newResourceHandlerFactory.d.ts.map +1 -0
  47. package/dist/mcp-server/resources/utils/newResourceHandlerFactory.js +103 -0
  48. package/dist/mcp-server/resources/utils/newResourceHandlerFactory.js.map +1 -0
  49. package/dist/mcp-server/resources/utils/resourceDefinition.d.ts +94 -0
  50. package/dist/mcp-server/resources/utils/resourceDefinition.d.ts.map +1 -0
  51. package/dist/mcp-server/resources/utils/resourceDefinition.js +2 -0
  52. package/dist/mcp-server/resources/utils/resourceDefinition.js.map +1 -0
  53. package/dist/mcp-server/resources/utils/resourceHandlerFactory.d.ts +14 -0
  54. package/dist/mcp-server/resources/utils/resourceHandlerFactory.d.ts.map +1 -0
  55. package/dist/mcp-server/resources/utils/resourceHandlerFactory.js +111 -0
  56. package/dist/mcp-server/resources/utils/resourceHandlerFactory.js.map +1 -0
  57. package/dist/mcp-server/roots/roots-registration.d.ts +22 -0
  58. package/dist/mcp-server/roots/roots-registration.d.ts.map +1 -0
  59. package/dist/mcp-server/roots/roots-registration.js +25 -0
  60. package/dist/mcp-server/roots/roots-registration.js.map +1 -0
  61. package/dist/mcp-server/server.d.ts +34 -0
  62. package/dist/mcp-server/server.d.ts.map +1 -0
  63. package/dist/mcp-server/server.js +62 -0
  64. package/dist/mcp-server/server.js.map +1 -0
  65. package/dist/mcp-server/tasks/core/sessionAwareTaskStore.d.ts +42 -0
  66. package/dist/mcp-server/tasks/core/sessionAwareTaskStore.d.ts.map +1 -0
  67. package/dist/mcp-server/tasks/core/sessionAwareTaskStore.js +70 -0
  68. package/dist/mcp-server/tasks/core/sessionAwareTaskStore.js.map +1 -0
  69. package/dist/mcp-server/tasks/core/storageBackedTaskStore.d.ts +109 -0
  70. package/dist/mcp-server/tasks/core/storageBackedTaskStore.d.ts.map +1 -0
  71. package/dist/mcp-server/tasks/core/storageBackedTaskStore.js +209 -0
  72. package/dist/mcp-server/tasks/core/storageBackedTaskStore.js.map +1 -0
  73. package/dist/mcp-server/tasks/core/taskManager.d.ts +103 -0
  74. package/dist/mcp-server/tasks/core/taskManager.d.ts.map +1 -0
  75. package/dist/mcp-server/tasks/core/taskManager.js +144 -0
  76. package/dist/mcp-server/tasks/core/taskManager.js.map +1 -0
  77. package/dist/mcp-server/tasks/core/taskTypes.d.ts +11 -0
  78. package/dist/mcp-server/tasks/core/taskTypes.d.ts.map +1 -0
  79. package/dist/mcp-server/tasks/core/taskTypes.js +13 -0
  80. package/dist/mcp-server/tasks/core/taskTypes.js.map +1 -0
  81. package/dist/mcp-server/tasks/utils/taskToolDefinition.d.ts +108 -0
  82. package/dist/mcp-server/tasks/utils/taskToolDefinition.d.ts.map +1 -0
  83. package/dist/mcp-server/tasks/utils/taskToolDefinition.js +14 -0
  84. package/dist/mcp-server/tasks/utils/taskToolDefinition.js.map +1 -0
  85. package/dist/mcp-server/tools/tool-registration.d.ts +49 -0
  86. package/dist/mcp-server/tools/tool-registration.d.ts.map +1 -0
  87. package/dist/mcp-server/tools/tool-registration.js +269 -0
  88. package/dist/mcp-server/tools/tool-registration.js.map +1 -0
  89. package/dist/mcp-server/tools/utils/newToolDefinition.d.ts +73 -0
  90. package/dist/mcp-server/tools/utils/newToolDefinition.d.ts.map +1 -0
  91. package/dist/mcp-server/tools/utils/newToolDefinition.js +45 -0
  92. package/dist/mcp-server/tools/utils/newToolDefinition.js.map +1 -0
  93. package/dist/mcp-server/tools/utils/newToolHandlerFactory.d.ts +33 -0
  94. package/dist/mcp-server/tools/utils/newToolHandlerFactory.d.ts.map +1 -0
  95. package/dist/mcp-server/tools/utils/newToolHandlerFactory.js +107 -0
  96. package/dist/mcp-server/tools/utils/newToolHandlerFactory.js.map +1 -0
  97. package/dist/mcp-server/tools/utils/toolDefinition.d.ts +118 -0
  98. package/dist/mcp-server/tools/utils/toolDefinition.d.ts.map +1 -0
  99. package/dist/mcp-server/tools/utils/toolDefinition.js +2 -0
  100. package/dist/mcp-server/tools/utils/toolDefinition.js.map +1 -0
  101. package/dist/mcp-server/tools/utils/toolHandlerFactory.d.ts +34 -0
  102. package/dist/mcp-server/tools/utils/toolHandlerFactory.d.ts.map +1 -0
  103. package/dist/mcp-server/tools/utils/toolHandlerFactory.js +68 -0
  104. package/dist/mcp-server/tools/utils/toolHandlerFactory.js.map +1 -0
  105. package/dist/mcp-server/transports/ITransport.d.ts +15 -0
  106. package/dist/mcp-server/transports/ITransport.d.ts.map +1 -0
  107. package/dist/mcp-server/transports/ITransport.js +2 -0
  108. package/dist/mcp-server/transports/ITransport.js.map +1 -0
  109. package/dist/mcp-server/transports/auth/authFactory.d.ts +11 -0
  110. package/dist/mcp-server/transports/auth/authFactory.d.ts.map +1 -0
  111. package/dist/mcp-server/transports/auth/authFactory.js +43 -0
  112. package/dist/mcp-server/transports/auth/authFactory.js.map +1 -0
  113. package/dist/mcp-server/transports/auth/authMiddleware.d.ts +24 -0
  114. package/dist/mcp-server/transports/auth/authMiddleware.d.ts.map +1 -0
  115. package/dist/mcp-server/transports/auth/authMiddleware.js +69 -0
  116. package/dist/mcp-server/transports/auth/authMiddleware.js.map +1 -0
  117. package/dist/mcp-server/transports/auth/lib/authContext.d.ts +34 -0
  118. package/dist/mcp-server/transports/auth/lib/authContext.d.ts.map +1 -0
  119. package/dist/mcp-server/transports/auth/lib/authContext.js +25 -0
  120. package/dist/mcp-server/transports/auth/lib/authContext.js.map +1 -0
  121. package/dist/mcp-server/transports/auth/lib/authTypes.d.ts +19 -0
  122. package/dist/mcp-server/transports/auth/lib/authTypes.d.ts.map +1 -0
  123. package/dist/mcp-server/transports/auth/lib/authTypes.js +2 -0
  124. package/dist/mcp-server/transports/auth/lib/authTypes.js.map +1 -0
  125. package/dist/mcp-server/transports/auth/lib/authUtils.d.ts +18 -0
  126. package/dist/mcp-server/transports/auth/lib/authUtils.d.ts.map +1 -0
  127. package/dist/mcp-server/transports/auth/lib/authUtils.js +64 -0
  128. package/dist/mcp-server/transports/auth/lib/authUtils.js.map +1 -0
  129. package/dist/mcp-server/transports/auth/lib/checkScopes.d.ts +25 -0
  130. package/dist/mcp-server/transports/auth/lib/checkScopes.d.ts.map +1 -0
  131. package/dist/mcp-server/transports/auth/lib/checkScopes.js +34 -0
  132. package/dist/mcp-server/transports/auth/lib/checkScopes.js.map +1 -0
  133. package/dist/mcp-server/transports/auth/lib/claimParser.d.ts +34 -0
  134. package/dist/mcp-server/transports/auth/lib/claimParser.d.ts.map +1 -0
  135. package/dist/mcp-server/transports/auth/lib/claimParser.js +58 -0
  136. package/dist/mcp-server/transports/auth/lib/claimParser.js.map +1 -0
  137. package/dist/mcp-server/transports/auth/lib/withAuth.d.ts +25 -0
  138. package/dist/mcp-server/transports/auth/lib/withAuth.d.ts.map +1 -0
  139. package/dist/mcp-server/transports/auth/lib/withAuth.js +30 -0
  140. package/dist/mcp-server/transports/auth/lib/withAuth.js.map +1 -0
  141. package/dist/mcp-server/transports/auth/strategies/authStrategy.d.ts +18 -0
  142. package/dist/mcp-server/transports/auth/strategies/authStrategy.d.ts.map +1 -0
  143. package/dist/mcp-server/transports/auth/strategies/authStrategy.js +2 -0
  144. package/dist/mcp-server/transports/auth/strategies/authStrategy.js.map +1 -0
  145. package/dist/mcp-server/transports/auth/strategies/jwtStrategy.d.ts +14 -0
  146. package/dist/mcp-server/transports/auth/strategies/jwtStrategy.d.ts.map +1 -0
  147. package/dist/mcp-server/transports/auth/strategies/jwtStrategy.js +86 -0
  148. package/dist/mcp-server/transports/auth/strategies/jwtStrategy.js.map +1 -0
  149. package/dist/mcp-server/transports/auth/strategies/oauthStrategy.d.ts +14 -0
  150. package/dist/mcp-server/transports/auth/strategies/oauthStrategy.d.ts.map +1 -0
  151. package/dist/mcp-server/transports/auth/strategies/oauthStrategy.js +113 -0
  152. package/dist/mcp-server/transports/auth/strategies/oauthStrategy.js.map +1 -0
  153. package/dist/mcp-server/transports/http/httpErrorHandler.d.ts +25 -0
  154. package/dist/mcp-server/transports/http/httpErrorHandler.d.ts.map +1 -0
  155. package/dist/mcp-server/transports/http/httpErrorHandler.js +112 -0
  156. package/dist/mcp-server/transports/http/httpErrorHandler.js.map +1 -0
  157. package/dist/mcp-server/transports/http/httpTransport.d.ts +47 -0
  158. package/dist/mcp-server/transports/http/httpTransport.d.ts.map +1 -0
  159. package/dist/mcp-server/transports/http/httpTransport.js +396 -0
  160. package/dist/mcp-server/transports/http/httpTransport.js.map +1 -0
  161. package/dist/mcp-server/transports/http/httpTypes.d.ts +17 -0
  162. package/dist/mcp-server/transports/http/httpTypes.d.ts.map +1 -0
  163. package/dist/mcp-server/transports/http/httpTypes.js +2 -0
  164. package/dist/mcp-server/transports/http/httpTypes.js.map +1 -0
  165. package/dist/mcp-server/transports/http/protectedResourceMetadata.d.ts +21 -0
  166. package/dist/mcp-server/transports/http/protectedResourceMetadata.d.ts.map +1 -0
  167. package/dist/mcp-server/transports/http/protectedResourceMetadata.js +44 -0
  168. package/dist/mcp-server/transports/http/protectedResourceMetadata.js.map +1 -0
  169. package/dist/mcp-server/transports/http/sessionIdUtils.d.ts +33 -0
  170. package/dist/mcp-server/transports/http/sessionIdUtils.d.ts.map +1 -0
  171. package/dist/mcp-server/transports/http/sessionIdUtils.js +54 -0
  172. package/dist/mcp-server/transports/http/sessionIdUtils.js.map +1 -0
  173. package/dist/mcp-server/transports/http/sessionStore.d.ts +87 -0
  174. package/dist/mcp-server/transports/http/sessionStore.d.ts.map +1 -0
  175. package/dist/mcp-server/transports/http/sessionStore.js +209 -0
  176. package/dist/mcp-server/transports/http/sessionStore.js.map +1 -0
  177. package/dist/mcp-server/transports/manager.d.ts +22 -0
  178. package/dist/mcp-server/transports/manager.d.ts.map +1 -0
  179. package/dist/mcp-server/transports/manager.js +62 -0
  180. package/dist/mcp-server/transports/manager.js.map +1 -0
  181. package/dist/mcp-server/transports/stdio/stdioTransport.d.ts +44 -0
  182. package/dist/mcp-server/transports/stdio/stdioTransport.d.ts.map +1 -0
  183. package/dist/mcp-server/transports/stdio/stdioTransport.js +63 -0
  184. package/dist/mcp-server/transports/stdio/stdioTransport.js.map +1 -0
  185. package/dist/services/graph/core/GraphService.d.ts +205 -0
  186. package/dist/services/graph/core/GraphService.d.ts.map +1 -0
  187. package/dist/services/graph/core/GraphService.js +231 -0
  188. package/dist/services/graph/core/GraphService.js.map +1 -0
  189. package/dist/services/graph/core/IGraphProvider.d.ts +295 -0
  190. package/dist/services/graph/core/IGraphProvider.d.ts.map +1 -0
  191. package/dist/services/graph/core/IGraphProvider.js +8 -0
  192. package/dist/services/graph/core/IGraphProvider.js.map +1 -0
  193. package/dist/services/graph/types.d.ts +107 -0
  194. package/dist/services/graph/types.d.ts.map +1 -0
  195. package/dist/services/graph/types.js +8 -0
  196. package/dist/services/graph/types.js.map +1 -0
  197. package/dist/services/llm/core/ILlmProvider.d.ts +86 -0
  198. package/dist/services/llm/core/ILlmProvider.d.ts.map +1 -0
  199. package/dist/services/llm/core/ILlmProvider.js +2 -0
  200. package/dist/services/llm/core/ILlmProvider.js.map +1 -0
  201. package/dist/services/llm/providers/openrouter.provider.d.ts +187 -0
  202. package/dist/services/llm/providers/openrouter.provider.d.ts.map +1 -0
  203. package/dist/services/llm/providers/openrouter.provider.js +302 -0
  204. package/dist/services/llm/providers/openrouter.provider.js.map +1 -0
  205. package/dist/services/llm/types.d.ts +16 -0
  206. package/dist/services/llm/types.d.ts.map +1 -0
  207. package/dist/services/llm/types.js +9 -0
  208. package/dist/services/llm/types.js.map +1 -0
  209. package/dist/services/speech/core/ISpeechProvider.d.ts +92 -0
  210. package/dist/services/speech/core/ISpeechProvider.d.ts.map +1 -0
  211. package/dist/services/speech/core/ISpeechProvider.js +34 -0
  212. package/dist/services/speech/core/ISpeechProvider.js.map +1 -0
  213. package/dist/services/speech/core/SpeechService.d.ts +87 -0
  214. package/dist/services/speech/core/SpeechService.d.ts.map +1 -0
  215. package/dist/services/speech/core/SpeechService.js +135 -0
  216. package/dist/services/speech/core/SpeechService.js.map +1 -0
  217. package/dist/services/speech/providers/elevenlabs.provider.d.ts +77 -0
  218. package/dist/services/speech/providers/elevenlabs.provider.d.ts.map +1 -0
  219. package/dist/services/speech/providers/elevenlabs.provider.js +199 -0
  220. package/dist/services/speech/providers/elevenlabs.provider.js.map +1 -0
  221. package/dist/services/speech/providers/whisper.provider.d.ts +94 -0
  222. package/dist/services/speech/providers/whisper.provider.d.ts.map +1 -0
  223. package/dist/services/speech/providers/whisper.provider.js +240 -0
  224. package/dist/services/speech/providers/whisper.provider.js.map +1 -0
  225. package/dist/services/speech/types.d.ts +173 -0
  226. package/dist/services/speech/types.d.ts.map +1 -0
  227. package/dist/services/speech/types.js +8 -0
  228. package/dist/services/speech/types.js.map +1 -0
  229. package/dist/storage/core/IStorageProvider.d.ts +159 -0
  230. package/dist/storage/core/IStorageProvider.d.ts.map +1 -0
  231. package/dist/storage/core/IStorageProvider.js +2 -0
  232. package/dist/storage/core/IStorageProvider.js.map +1 -0
  233. package/dist/storage/core/StorageService.d.ts +22 -0
  234. package/dist/storage/core/StorageService.d.ts.map +1 -0
  235. package/dist/storage/core/StorageService.js +151 -0
  236. package/dist/storage/core/StorageService.js.map +1 -0
  237. package/dist/storage/core/storageFactory.d.ts +66 -0
  238. package/dist/storage/core/storageFactory.d.ts.map +1 -0
  239. package/dist/storage/core/storageFactory.js +122 -0
  240. package/dist/storage/core/storageFactory.js.map +1 -0
  241. package/dist/storage/core/storageValidation.d.ts +77 -0
  242. package/dist/storage/core/storageValidation.d.ts.map +1 -0
  243. package/dist/storage/core/storageValidation.js +303 -0
  244. package/dist/storage/core/storageValidation.js.map +1 -0
  245. package/dist/storage/providers/cloudflare/d1Provider.d.ts +94 -0
  246. package/dist/storage/providers/cloudflare/d1Provider.d.ts.map +1 -0
  247. package/dist/storage/providers/cloudflare/d1Provider.js +347 -0
  248. package/dist/storage/providers/cloudflare/d1Provider.js.map +1 -0
  249. package/dist/storage/providers/cloudflare/kvProvider.d.ts +21 -0
  250. package/dist/storage/providers/cloudflare/kvProvider.d.ts.map +1 -0
  251. package/dist/storage/providers/cloudflare/kvProvider.js +183 -0
  252. package/dist/storage/providers/cloudflare/kvProvider.js.map +1 -0
  253. package/dist/storage/providers/cloudflare/r2Provider.d.ts +28 -0
  254. package/dist/storage/providers/cloudflare/r2Provider.d.ts.map +1 -0
  255. package/dist/storage/providers/cloudflare/r2Provider.js +222 -0
  256. package/dist/storage/providers/cloudflare/r2Provider.js.map +1 -0
  257. package/dist/storage/providers/fileSystem/fileSystemProvider.d.ts +20 -0
  258. package/dist/storage/providers/fileSystem/fileSystemProvider.d.ts.map +1 -0
  259. package/dist/storage/providers/fileSystem/fileSystemProvider.js +282 -0
  260. package/dist/storage/providers/fileSystem/fileSystemProvider.js.map +1 -0
  261. package/dist/storage/providers/inMemory/inMemoryProvider.d.ts +21 -0
  262. package/dist/storage/providers/inMemory/inMemoryProvider.d.ts.map +1 -0
  263. package/dist/storage/providers/inMemory/inMemoryProvider.js +139 -0
  264. package/dist/storage/providers/inMemory/inMemoryProvider.js.map +1 -0
  265. package/dist/storage/providers/supabase/supabase.types.d.ts +49 -0
  266. package/dist/storage/providers/supabase/supabase.types.d.ts.map +1 -0
  267. package/dist/storage/providers/supabase/supabase.types.js +8 -0
  268. package/dist/storage/providers/supabase/supabase.types.js.map +1 -0
  269. package/dist/storage/providers/supabase/supabaseProvider.d.ts +24 -0
  270. package/dist/storage/providers/supabase/supabaseProvider.d.ts.map +1 -0
  271. package/dist/storage/providers/supabase/supabaseProvider.js +209 -0
  272. package/dist/storage/providers/supabase/supabaseProvider.js.map +1 -0
  273. package/dist/testing/index.d.ts +53 -0
  274. package/dist/testing/index.d.ts.map +1 -0
  275. package/dist/testing/index.js +132 -0
  276. package/dist/testing/index.js.map +1 -0
  277. package/dist/types-global/errors.d.ts +83 -0
  278. package/dist/types-global/errors.d.ts.map +1 -0
  279. package/dist/types-global/errors.js +113 -0
  280. package/dist/types-global/errors.js.map +1 -0
  281. package/dist/utils/formatting/diffFormatter.d.ts +227 -0
  282. package/dist/utils/formatting/diffFormatter.d.ts.map +1 -0
  283. package/dist/utils/formatting/diffFormatter.js +369 -0
  284. package/dist/utils/formatting/diffFormatter.js.map +1 -0
  285. package/dist/utils/formatting/index.d.ts +9 -0
  286. package/dist/utils/formatting/index.d.ts.map +1 -0
  287. package/dist/utils/formatting/index.js +9 -0
  288. package/dist/utils/formatting/index.js.map +1 -0
  289. package/dist/utils/formatting/markdownBuilder.d.ts +543 -0
  290. package/dist/utils/formatting/markdownBuilder.d.ts.map +1 -0
  291. package/dist/utils/formatting/markdownBuilder.js +674 -0
  292. package/dist/utils/formatting/markdownBuilder.js.map +1 -0
  293. package/dist/utils/formatting/tableFormatter.d.ts +261 -0
  294. package/dist/utils/formatting/tableFormatter.d.ts.map +1 -0
  295. package/dist/utils/formatting/tableFormatter.js +456 -0
  296. package/dist/utils/formatting/tableFormatter.js.map +1 -0
  297. package/dist/utils/formatting/treeFormatter.d.ts +344 -0
  298. package/dist/utils/formatting/treeFormatter.d.ts.map +1 -0
  299. package/dist/utils/formatting/treeFormatter.js +400 -0
  300. package/dist/utils/formatting/treeFormatter.js.map +1 -0
  301. package/dist/utils/internal/encoding.d.ts +42 -0
  302. package/dist/utils/internal/encoding.d.ts.map +1 -0
  303. package/dist/utils/internal/encoding.js +87 -0
  304. package/dist/utils/internal/encoding.js.map +1 -0
  305. package/dist/utils/internal/error-handler/errorHandler.d.ts +140 -0
  306. package/dist/utils/internal/error-handler/errorHandler.d.ts.map +1 -0
  307. package/dist/utils/internal/error-handler/errorHandler.js +318 -0
  308. package/dist/utils/internal/error-handler/errorHandler.js.map +1 -0
  309. package/dist/utils/internal/error-handler/helpers.d.ts +98 -0
  310. package/dist/utils/internal/error-handler/helpers.d.ts.map +1 -0
  311. package/dist/utils/internal/error-handler/helpers.js +214 -0
  312. package/dist/utils/internal/error-handler/helpers.js.map +1 -0
  313. package/dist/utils/internal/error-handler/mappings.d.ts +85 -0
  314. package/dist/utils/internal/error-handler/mappings.d.ts.map +1 -0
  315. package/dist/utils/internal/error-handler/mappings.js +234 -0
  316. package/dist/utils/internal/error-handler/mappings.js.map +1 -0
  317. package/dist/utils/internal/error-handler/types.d.ts +160 -0
  318. package/dist/utils/internal/error-handler/types.d.ts.map +1 -0
  319. package/dist/utils/internal/error-handler/types.js +6 -0
  320. package/dist/utils/internal/error-handler/types.js.map +1 -0
  321. package/dist/utils/internal/health.d.ts +60 -0
  322. package/dist/utils/internal/health.d.ts.map +1 -0
  323. package/dist/utils/internal/health.js +46 -0
  324. package/dist/utils/internal/health.js.map +1 -0
  325. package/dist/utils/internal/logger.d.ts +300 -0
  326. package/dist/utils/internal/logger.d.ts.map +1 -0
  327. package/dist/utils/internal/logger.js +573 -0
  328. package/dist/utils/internal/logger.js.map +1 -0
  329. package/dist/utils/internal/performance.d.ts +78 -0
  330. package/dist/utils/internal/performance.d.ts.map +1 -0
  331. package/dist/utils/internal/performance.js +227 -0
  332. package/dist/utils/internal/performance.js.map +1 -0
  333. package/dist/utils/internal/requestContext.d.ts +200 -0
  334. package/dist/utils/internal/requestContext.d.ts.map +1 -0
  335. package/dist/utils/internal/requestContext.js +163 -0
  336. package/dist/utils/internal/requestContext.js.map +1 -0
  337. package/dist/utils/internal/runtime.d.ts +49 -0
  338. package/dist/utils/internal/runtime.d.ts.map +1 -0
  339. package/dist/utils/internal/runtime.js +90 -0
  340. package/dist/utils/internal/runtime.js.map +1 -0
  341. package/dist/utils/internal/startupBanner.d.ts +23 -0
  342. package/dist/utils/internal/startupBanner.d.ts.map +1 -0
  343. package/dist/utils/internal/startupBanner.js +34 -0
  344. package/dist/utils/internal/startupBanner.js.map +1 -0
  345. package/dist/utils/metrics/tokenCounter.d.ts +97 -0
  346. package/dist/utils/metrics/tokenCounter.d.ts.map +1 -0
  347. package/dist/utils/metrics/tokenCounter.js +162 -0
  348. package/dist/utils/metrics/tokenCounter.js.map +1 -0
  349. package/dist/utils/network/fetchWithTimeout.d.ts +91 -0
  350. package/dist/utils/network/fetchWithTimeout.d.ts.map +1 -0
  351. package/dist/utils/network/fetchWithTimeout.js +305 -0
  352. package/dist/utils/network/fetchWithTimeout.js.map +1 -0
  353. package/dist/utils/pagination/pagination.d.ts +157 -0
  354. package/dist/utils/pagination/pagination.d.ts.map +1 -0
  355. package/dist/utils/pagination/pagination.js +191 -0
  356. package/dist/utils/pagination/pagination.js.map +1 -0
  357. package/dist/utils/parsing/csvParser.d.ts +84 -0
  358. package/dist/utils/parsing/csvParser.d.ts.map +1 -0
  359. package/dist/utils/parsing/csvParser.js +132 -0
  360. package/dist/utils/parsing/csvParser.js.map +1 -0
  361. package/dist/utils/parsing/dateParser.d.ts +103 -0
  362. package/dist/utils/parsing/dateParser.d.ts.map +1 -0
  363. package/dist/utils/parsing/dateParser.js +142 -0
  364. package/dist/utils/parsing/dateParser.js.map +1 -0
  365. package/dist/utils/parsing/frontmatterParser.d.ts +91 -0
  366. package/dist/utils/parsing/frontmatterParser.d.ts.map +1 -0
  367. package/dist/utils/parsing/frontmatterParser.js +163 -0
  368. package/dist/utils/parsing/frontmatterParser.js.map +1 -0
  369. package/dist/utils/parsing/index.d.ts +15 -0
  370. package/dist/utils/parsing/index.d.ts.map +1 -0
  371. package/dist/utils/parsing/index.js +15 -0
  372. package/dist/utils/parsing/index.js.map +1 -0
  373. package/dist/utils/parsing/jsonParser.d.ts +115 -0
  374. package/dist/utils/parsing/jsonParser.d.ts.map +1 -0
  375. package/dist/utils/parsing/jsonParser.js +177 -0
  376. package/dist/utils/parsing/jsonParser.js.map +1 -0
  377. package/dist/utils/parsing/pdfParser.d.ts +563 -0
  378. package/dist/utils/parsing/pdfParser.d.ts.map +1 -0
  379. package/dist/utils/parsing/pdfParser.js +775 -0
  380. package/dist/utils/parsing/pdfParser.js.map +1 -0
  381. package/dist/utils/parsing/thinkBlock.d.ts +31 -0
  382. package/dist/utils/parsing/thinkBlock.d.ts.map +1 -0
  383. package/dist/utils/parsing/thinkBlock.js +31 -0
  384. package/dist/utils/parsing/thinkBlock.js.map +1 -0
  385. package/dist/utils/parsing/xmlParser.d.ts +69 -0
  386. package/dist/utils/parsing/xmlParser.d.ts.map +1 -0
  387. package/dist/utils/parsing/xmlParser.js +140 -0
  388. package/dist/utils/parsing/xmlParser.js.map +1 -0
  389. package/dist/utils/parsing/yamlParser.d.ts +64 -0
  390. package/dist/utils/parsing/yamlParser.d.ts.map +1 -0
  391. package/dist/utils/parsing/yamlParser.js +129 -0
  392. package/dist/utils/parsing/yamlParser.js.map +1 -0
  393. package/dist/utils/scheduling/scheduler.d.ts +174 -0
  394. package/dist/utils/scheduling/scheduler.d.ts.map +1 -0
  395. package/dist/utils/scheduling/scheduler.js +248 -0
  396. package/dist/utils/scheduling/scheduler.js.map +1 -0
  397. package/dist/utils/security/idGenerator.d.ts +189 -0
  398. package/dist/utils/security/idGenerator.d.ts.map +1 -0
  399. package/dist/utils/security/idGenerator.js +301 -0
  400. package/dist/utils/security/idGenerator.js.map +1 -0
  401. package/dist/utils/security/index.d.ts +8 -0
  402. package/dist/utils/security/index.d.ts.map +1 -0
  403. package/dist/utils/security/index.js +8 -0
  404. package/dist/utils/security/index.js.map +1 -0
  405. package/dist/utils/security/rateLimiter.d.ts +171 -0
  406. package/dist/utils/security/rateLimiter.d.ts.map +1 -0
  407. package/dist/utils/security/rateLimiter.js +294 -0
  408. package/dist/utils/security/rateLimiter.js.map +1 -0
  409. package/dist/utils/security/sanitization.d.ts +430 -0
  410. package/dist/utils/security/sanitization.d.ts.map +1 -0
  411. package/dist/utils/security/sanitization.js +759 -0
  412. package/dist/utils/security/sanitization.js.map +1 -0
  413. package/dist/utils/telemetry/index.d.ts +12 -0
  414. package/dist/utils/telemetry/index.d.ts.map +1 -0
  415. package/dist/utils/telemetry/index.js +12 -0
  416. package/dist/utils/telemetry/index.js.map +1 -0
  417. package/dist/utils/telemetry/instrumentation.d.ts +62 -0
  418. package/dist/utils/telemetry/instrumentation.d.ts.map +1 -0
  419. package/dist/utils/telemetry/instrumentation.js +223 -0
  420. package/dist/utils/telemetry/instrumentation.js.map +1 -0
  421. package/dist/utils/telemetry/metrics.d.ts +170 -0
  422. package/dist/utils/telemetry/metrics.d.ts.map +1 -0
  423. package/dist/utils/telemetry/metrics.js +205 -0
  424. package/dist/utils/telemetry/metrics.js.map +1 -0
  425. package/dist/utils/telemetry/semconv.d.ts +147 -0
  426. package/dist/utils/telemetry/semconv.d.ts.map +1 -0
  427. package/dist/utils/telemetry/semconv.js +159 -0
  428. package/dist/utils/telemetry/semconv.js.map +1 -0
  429. package/dist/utils/telemetry/trace.d.ts +141 -0
  430. package/dist/utils/telemetry/trace.d.ts.map +1 -0
  431. package/dist/utils/telemetry/trace.js +193 -0
  432. package/dist/utils/telemetry/trace.js.map +1 -0
  433. package/dist/utils/types/guards.d.ts +209 -0
  434. package/dist/utils/types/guards.d.ts.map +1 -0
  435. package/dist/utils/types/guards.js +229 -0
  436. package/dist/utils/types/guards.js.map +1 -0
  437. package/dist/utils/types/index.d.ts +6 -0
  438. package/dist/utils/types/index.d.ts.map +1 -0
  439. package/dist/utils/types/index.js +6 -0
  440. package/dist/utils/types/index.js.map +1 -0
  441. package/dist/worker.d.ts +59 -0
  442. package/dist/worker.d.ts.map +1 -0
  443. package/dist/worker.js +216 -0
  444. package/dist/worker.js.map +1 -0
  445. package/package.json +377 -0
  446. package/skills/README.md +38 -0
  447. package/skills/add-export/SKILL.md +49 -0
  448. package/skills/add-prompt/SKILL.md +97 -0
  449. package/skills/add-provider/SKILL.md +53 -0
  450. package/skills/add-resource/SKILL.md +107 -0
  451. package/skills/add-service/SKILL.md +113 -0
  452. package/skills/add-tool/SKILL.md +110 -0
  453. package/skills/api-auth/SKILL.md +173 -0
  454. package/skills/api-config/SKILL.md +68 -0
  455. package/skills/api-context/SKILL.md +321 -0
  456. package/skills/api-errors/SKILL.md +146 -0
  457. package/skills/api-services/SKILL.md +24 -0
  458. package/skills/api-services/references/graph.md +124 -0
  459. package/skills/api-services/references/llm.md +46 -0
  460. package/skills/api-services/references/speech.md +72 -0
  461. package/skills/api-testing/SKILL.md +263 -0
  462. package/skills/api-utils/SKILL.md +106 -0
  463. package/skills/api-utils/references/formatting.md +237 -0
  464. package/skills/api-utils/references/parsing.md +263 -0
  465. package/skills/api-utils/references/security.md +226 -0
  466. package/skills/api-workers/SKILL.md +165 -0
  467. package/skills/devcheck/SKILL.md +31 -0
  468. package/skills/maintenance/SKILL.md +52 -0
  469. package/skills/migrate-mcp-ts-template/SKILL.md +131 -0
  470. package/skills/release/SKILL.md +67 -0
  471. package/skills/setup/SKILL.md +89 -0
  472. package/skills/walkthrough-init/SKILL.md +50 -0
  473. package/templates/.env.example +17 -0
  474. package/templates/AGENTS.md +113 -0
  475. package/templates/CLAUDE.md +113 -0
  476. package/templates/_tsconfig.json +33 -0
  477. package/templates/biome.template.json +43 -0
  478. package/templates/package.json +26 -0
  479. package/templates/src/index.ts +16 -0
  480. package/templates/src/mcp-server/prompts/definitions/echo.prompt.ts +19 -0
  481. package/templates/src/mcp-server/resources/definitions/echo.resource.ts +30 -0
  482. package/templates/src/mcp-server/tools/definitions/echo.tool.ts +24 -0
  483. package/templates/vitest.config.ts +12 -0
  484. package/tsconfig.base.json +44 -0
  485. package/vitest.config.base.ts +38 -0
@@ -0,0 +1,187 @@
1
+ import type { ChatCompletion, ChatCompletionChunk } from 'openai/resources/chat/completions';
2
+ import type { Stream } from 'openai/streaming';
3
+ import type { config as ConfigType } from '../../../config/index.js';
4
+ import type { ILlmProvider, OpenRouterChatParams } from '../../../services/llm/core/ILlmProvider.js';
5
+ import type { logger as LoggerType } from '../../../utils/internal/logger.js';
6
+ import { type RequestContext } from '../../../utils/internal/requestContext.js';
7
+ import type { RateLimiter } from '../../../utils/security/rateLimiter.js';
8
+ /**
9
+ * Construction options for the underlying `OpenAI` client pointed at OpenRouter.
10
+ * Passed internally by `initClient()` — not exposed as a public constructor parameter,
11
+ * but exported so callers can reference the shape if needed.
12
+ */
13
+ export interface OpenRouterClientOptions {
14
+ /** OpenRouter API key (value of `OPENROUTER_API_KEY`). */
15
+ apiKey: string;
16
+ /**
17
+ * Base URL for the OpenRouter API. Defaults to `https://openrouter.ai/api/v1`
18
+ * when not provided.
19
+ */
20
+ baseURL?: string;
21
+ /**
22
+ * Human-readable name of the calling application, sent as the `X-Title` request
23
+ * header for OpenRouter analytics and attribution.
24
+ */
25
+ siteName?: string;
26
+ /**
27
+ * URL of the calling application, sent as the `HTTP-Referer` request header for
28
+ * OpenRouter analytics and attribution.
29
+ */
30
+ siteUrl?: string;
31
+ }
32
+ /**
33
+ * LLM provider implementation backed by the OpenRouter API.
34
+ *
35
+ * Implements `ILlmProvider` so it can be used anywhere the framework expects a
36
+ * generic LLM provider. The `openai` SDK is loaded lazily on first use; the
37
+ * resulting `OpenAI` client is cached for the lifetime of the instance.
38
+ *
39
+ * Default generation parameters (`model`, `temperature`, `top_p`, `max_tokens`,
40
+ * `top_k`, `min_p`) are read from the application config at construction time and
41
+ * applied to every request unless the caller explicitly overrides them. Passing
42
+ * `null` for an OpenAI-typed field (e.g. `temperature: null`) clears that default.
43
+ *
44
+ * @example
45
+ * ```ts
46
+ * const provider = new OpenRouterProvider(rateLimiter, config, logger);
47
+ * const completion = await provider.chatCompletion(
48
+ * { model: 'openai/gpt-4o', messages: [{ role: 'user', content: 'Hello' }] },
49
+ * ctx,
50
+ * );
51
+ * ```
52
+ */
53
+ export declare class OpenRouterProvider implements ILlmProvider {
54
+ private rateLimiter;
55
+ private config;
56
+ private logger;
57
+ /** Cached `OpenAI` client instance. Undefined until the first request. */
58
+ private client;
59
+ /**
60
+ * In-flight initialization promise. Guards against concurrent calls racing to
61
+ * create the client simultaneously. Reset to `undefined` if `initClient` throws,
62
+ * so the next call can retry.
63
+ */
64
+ private clientInitPromise;
65
+ /** Default generation parameters sourced from app config at construction time. */
66
+ private readonly defaultParams;
67
+ /**
68
+ * Creates a new `OpenRouterProvider` instance.
69
+ *
70
+ * @param rateLimiter - Rate limiter used to throttle outbound API calls per
71
+ * client/tenant key.
72
+ * @param config - Application config object; must have `openrouterApiKey` set,
73
+ * and may have `llmDefault*` fields for generation defaults.
74
+ * @param logger - Application logger for lifecycle and interaction logging.
75
+ * @throws {McpError} `ConfigurationError` if `openrouterApiKey` is absent in config.
76
+ */
77
+ constructor(rateLimiter: RateLimiter, config: typeof ConfigType, logger: typeof LoggerType);
78
+ /**
79
+ * Returns the initialized `OpenAI` client, initializing it on first call.
80
+ * Concurrent callers share a single initialization promise to avoid duplicate
81
+ * client construction.
82
+ *
83
+ * @returns The ready-to-use `OpenAI` client.
84
+ * @throws {McpError} `ConfigurationError` if client initialization fails.
85
+ */
86
+ private ensureClient;
87
+ /**
88
+ * Performs the one-time initialization of the `OpenAI` client configured for
89
+ * the OpenRouter base URL. Lazily imports the `openai` package, constructs the
90
+ * client with API key and optional site metadata headers, and stores the result
91
+ * in `this.client`.
92
+ *
93
+ * If initialization fails, `clientInitPromise` is reset so the next call to
94
+ * `ensureClient()` can attempt again.
95
+ *
96
+ * @returns The newly constructed `OpenAI` client.
97
+ * @throws {McpError} `ConfigurationError` if the `openai` package is missing or
98
+ * client construction throws.
99
+ */
100
+ private initClient;
101
+ /**
102
+ * Merges caller-supplied parameters with instance-level defaults. OpenAI-typed
103
+ * fields (`model`, `temperature`, `top_p`, `max_tokens`) fall back to the
104
+ * corresponding `defaultParams` value when omitted. Passing `null` explicitly
105
+ * clears the default (mapped to `undefined` in the result object so the field is
106
+ * omitted from the API request).
107
+ *
108
+ * OpenRouter-specific fields not present in the OpenAI type definitions
109
+ * (`top_k`, `min_p`) are applied from defaults only when not already present in
110
+ * the incoming params.
111
+ *
112
+ * @param params - Raw parameters from the caller before defaults are applied.
113
+ * @returns A new parameter object with defaults merged in, ready to send to the
114
+ * OpenRouter API.
115
+ */
116
+ private _prepareApiParameters;
117
+ /**
118
+ * Dispatches a single chat completion call to the OpenRouter API via the
119
+ * provided `OpenAI` client. Logs the outbound request via `logInteraction`.
120
+ * For non-streaming calls, awaits the response and logs it before returning.
121
+ * For streaming calls, returns the `Stream` immediately; the caller is
122
+ * responsible for consuming and logging the stream (see `chatCompletionStream`).
123
+ *
124
+ * @param client - Initialized `OpenAI` client to use for the request.
125
+ * @param params - Fully-prepared API parameters (defaults already merged).
126
+ * @param context - Request context for correlated log entries.
127
+ * @returns `ChatCompletion` for non-streaming; `Stream<ChatCompletionChunk>` for streaming.
128
+ * @throws Propagates any error thrown by the OpenAI SDK.
129
+ */
130
+ private _openRouterChatCompletionLogic;
131
+ /**
132
+ * Sends a chat completion request to OpenRouter. Enforces rate limiting keyed
133
+ * on `context.auth?.clientId`, `context.tenantId`, or the global fallback key
134
+ * `'openrouter_global'`. Applies generation defaults via `_prepareApiParameters`
135
+ * before dispatching.
136
+ *
137
+ * Wraps execution in `ErrorHandler.tryCatch` for consistent error formatting and
138
+ * structured logging. Input params are sanitized before logging.
139
+ *
140
+ * @param params - Chat completion parameters (streaming or non-streaming).
141
+ * @param context - Request context for rate-limit keying, logging, and tracing.
142
+ * @returns `ChatCompletion` when `params.stream` is falsy; `Stream<ChatCompletionChunk>`
143
+ * when `params.stream` is `true`.
144
+ * @throws {McpError} `RateLimited` if the rate limit is exceeded.
145
+ * @throws {McpError} `ConfigurationError` if the OpenAI client cannot be initialized.
146
+ * @throws {McpError} `ServiceUnavailable` if the OpenRouter API call fails.
147
+ *
148
+ * @example
149
+ * ```ts
150
+ * const result = await provider.chatCompletion(
151
+ * { model: 'openai/gpt-4o', messages: [{ role: 'user', content: 'Hello' }] },
152
+ * ctx,
153
+ * ) as ChatCompletion;
154
+ * console.log(result.choices[0].message.content);
155
+ * ```
156
+ */
157
+ chatCompletion(params: OpenRouterChatParams, context: RequestContext): Promise<ChatCompletion | Stream<ChatCompletionChunk>>;
158
+ /**
159
+ * Sends a streaming chat completion request to OpenRouter and returns an async
160
+ * generator that yields `ChatCompletionChunk` objects as they arrive.
161
+ *
162
+ * Internally delegates to `chatCompletion` with `stream: true` forced, then
163
+ * wraps the resulting `Stream` in a generator that collects all chunks and logs
164
+ * the full response (via `logInteraction`) in the generator's `finally` block
165
+ * once the stream is exhausted or the consumer breaks out early.
166
+ *
167
+ * @param params - Chat completion parameters. `stream` is overridden to `true`.
168
+ * @param context - Request context for rate-limit keying, logging, and tracing.
169
+ * @returns An async iterable that yields `ChatCompletionChunk` objects.
170
+ * @throws {McpError} `RateLimited` if the rate limit is exceeded.
171
+ * @throws {McpError} `ConfigurationError` if the OpenAI client cannot be initialized.
172
+ * @throws {McpError} `ServiceUnavailable` if the OpenRouter API call fails.
173
+ *
174
+ * @example
175
+ * ```ts
176
+ * const stream = await provider.chatCompletionStream(
177
+ * { model: 'openai/gpt-4o', messages: [{ role: 'user', content: 'Hello' }] },
178
+ * ctx,
179
+ * );
180
+ * for await (const chunk of stream) {
181
+ * process.stdout.write(chunk.choices[0]?.delta?.content ?? '');
182
+ * }
183
+ * ```
184
+ */
185
+ chatCompletionStream(params: OpenRouterChatParams, context: RequestContext): Promise<AsyncIterable<ChatCompletionChunk>>;
186
+ }
187
+ //# sourceMappingURL=openrouter.provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openrouter.provider.d.ts","sourceRoot":"","sources":["../../../../src/services/llm/providers/openrouter.provider.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAC7F,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE/C,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cAAc,GACtB,OAAO,CAAC,cAAc,GAAG,MAAM,CAAC,mBAAmB,CAAC,CAAC;IAgBxD;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACU,oBAAoB,CAC/B,MAAM,EAAE,oBAAoB,EAC5B,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,aAAa,CAAC,mBAAmB,CAAC,CAAC;CA2B/C"}
@@ -0,0 +1,302 @@
1
+ import { JsonRpcErrorCode, McpError } from '../../../types-global/errors.js';
2
+ import { ErrorHandler } from '../../../utils/internal/error-handler/errorHandler.js';
3
+ import { requestContextService } from '../../../utils/internal/requestContext.js';
4
+ import { sanitization } from '../../../utils/security/sanitization.js';
5
+ /**
6
+ * Module-level cache for the lazily-imported `openai` package. Undefined until the
7
+ * first call to `getOpenAI()`. Retained across calls to avoid repeated dynamic imports.
8
+ */
9
+ let _openai;
10
+ /**
11
+ * Lazily imports and returns the `OpenAI` default export from the `openai` package.
12
+ * The import is deferred so that `openai` remains an optional peer dependency —
13
+ * servers that never call an LLM method pay no startup cost.
14
+ *
15
+ * @returns The `OpenAI` constructor (default export of the `openai` package).
16
+ * @throws {McpError} `ConfigurationError` if the `openai` package is not installed.
17
+ */
18
+ async function getOpenAI() {
19
+ _openai ??= await import('openai').catch(() => {
20
+ throw new McpError(JsonRpcErrorCode.ConfigurationError, 'Install "openai" to use the OpenRouter LLM provider: bun add openai');
21
+ });
22
+ return _openai.default;
23
+ }
24
+ /**
25
+ * LLM provider implementation backed by the OpenRouter API.
26
+ *
27
+ * Implements `ILlmProvider` so it can be used anywhere the framework expects a
28
+ * generic LLM provider. The `openai` SDK is loaded lazily on first use; the
29
+ * resulting `OpenAI` client is cached for the lifetime of the instance.
30
+ *
31
+ * Default generation parameters (`model`, `temperature`, `top_p`, `max_tokens`,
32
+ * `top_k`, `min_p`) are read from the application config at construction time and
33
+ * applied to every request unless the caller explicitly overrides them. Passing
34
+ * `null` for an OpenAI-typed field (e.g. `temperature: null`) clears that default.
35
+ *
36
+ * @example
37
+ * ```ts
38
+ * const provider = new OpenRouterProvider(rateLimiter, config, logger);
39
+ * const completion = await provider.chatCompletion(
40
+ * { model: 'openai/gpt-4o', messages: [{ role: 'user', content: 'Hello' }] },
41
+ * ctx,
42
+ * );
43
+ * ```
44
+ */
45
+ export class OpenRouterProvider {
46
+ rateLimiter;
47
+ config;
48
+ logger;
49
+ /** Cached `OpenAI` client instance. Undefined until the first request. */
50
+ client;
51
+ /**
52
+ * In-flight initialization promise. Guards against concurrent calls racing to
53
+ * create the client simultaneously. Reset to `undefined` if `initClient` throws,
54
+ * so the next call can retry.
55
+ */
56
+ clientInitPromise;
57
+ /** Default generation parameters sourced from app config at construction time. */
58
+ defaultParams;
59
+ /**
60
+ * Creates a new `OpenRouterProvider` instance.
61
+ *
62
+ * @param rateLimiter - Rate limiter used to throttle outbound API calls per
63
+ * client/tenant key.
64
+ * @param config - Application config object; must have `openrouterApiKey` set,
65
+ * and may have `llmDefault*` fields for generation defaults.
66
+ * @param logger - Application logger for lifecycle and interaction logging.
67
+ * @throws {McpError} `ConfigurationError` if `openrouterApiKey` is absent in config.
68
+ */
69
+ constructor(rateLimiter, config, logger) {
70
+ this.rateLimiter = rateLimiter;
71
+ this.config = config;
72
+ this.logger = logger;
73
+ const context = requestContextService.createRequestContext({
74
+ operation: 'OpenRouterProvider.constructor',
75
+ });
76
+ if (!this.config.openrouterApiKey) {
77
+ this.logger.fatal('OpenRouter API key is not configured. Please set OPENROUTER_API_KEY.', context);
78
+ throw new McpError(JsonRpcErrorCode.ConfigurationError, 'OpenRouter API key is not configured.', context);
79
+ }
80
+ this.defaultParams = {
81
+ model: this.config.llmDefaultModel,
82
+ temperature: this.config.llmDefaultTemperature,
83
+ topP: this.config.llmDefaultTopP,
84
+ maxTokens: this.config.llmDefaultMaxTokens,
85
+ topK: this.config.llmDefaultTopK,
86
+ minP: this.config.llmDefaultMinP,
87
+ };
88
+ this.logger.info('OpenRouter provider instance created and ready.', context);
89
+ }
90
+ /**
91
+ * Returns the initialized `OpenAI` client, initializing it on first call.
92
+ * Concurrent callers share a single initialization promise to avoid duplicate
93
+ * client construction.
94
+ *
95
+ * @returns The ready-to-use `OpenAI` client.
96
+ * @throws {McpError} `ConfigurationError` if client initialization fails.
97
+ */
98
+ async ensureClient() {
99
+ if (this.client)
100
+ return this.client;
101
+ this.clientInitPromise ??= this.initClient();
102
+ return await this.clientInitPromise;
103
+ }
104
+ /**
105
+ * Performs the one-time initialization of the `OpenAI` client configured for
106
+ * the OpenRouter base URL. Lazily imports the `openai` package, constructs the
107
+ * client with API key and optional site metadata headers, and stores the result
108
+ * in `this.client`.
109
+ *
110
+ * If initialization fails, `clientInitPromise` is reset so the next call to
111
+ * `ensureClient()` can attempt again.
112
+ *
113
+ * @returns The newly constructed `OpenAI` client.
114
+ * @throws {McpError} `ConfigurationError` if the `openai` package is missing or
115
+ * client construction throws.
116
+ */
117
+ async initClient() {
118
+ const context = requestContextService.createRequestContext({
119
+ operation: 'OpenRouterProvider.initClient',
120
+ });
121
+ try {
122
+ const OpenAIClass = await getOpenAI();
123
+ const options = {
124
+ apiKey: this.config.openrouterApiKey,
125
+ siteUrl: this.config.openrouterAppUrl,
126
+ siteName: this.config.openrouterAppName,
127
+ };
128
+ this.client = new OpenAIClass({
129
+ baseURL: options.baseURL ?? 'https://openrouter.ai/api/v1',
130
+ apiKey: options.apiKey,
131
+ defaultHeaders: {
132
+ 'HTTP-Referer': options.siteUrl,
133
+ 'X-Title': options.siteName,
134
+ },
135
+ maxRetries: 0,
136
+ });
137
+ return this.client;
138
+ }
139
+ catch (e) {
140
+ this.clientInitPromise = undefined;
141
+ const error = e instanceof Error ? e : new Error(String(e));
142
+ this.logger.error('Failed to construct OpenRouter client', {
143
+ ...context,
144
+ error: error.message,
145
+ });
146
+ throw new McpError(JsonRpcErrorCode.ConfigurationError, 'Failed to construct OpenRouter client. Please check the configuration.', { cause: error });
147
+ }
148
+ }
149
+ // --- PRIVATE METHODS ---
150
+ /**
151
+ * Merges caller-supplied parameters with instance-level defaults. OpenAI-typed
152
+ * fields (`model`, `temperature`, `top_p`, `max_tokens`) fall back to the
153
+ * corresponding `defaultParams` value when omitted. Passing `null` explicitly
154
+ * clears the default (mapped to `undefined` in the result object so the field is
155
+ * omitted from the API request).
156
+ *
157
+ * OpenRouter-specific fields not present in the OpenAI type definitions
158
+ * (`top_k`, `min_p`) are applied from defaults only when not already present in
159
+ * the incoming params.
160
+ *
161
+ * @param params - Raw parameters from the caller before defaults are applied.
162
+ * @returns A new parameter object with defaults merged in, ready to send to the
163
+ * OpenRouter API.
164
+ */
165
+ _prepareApiParameters(params) {
166
+ const { model, temperature, top_p: topP, max_tokens: maxTokens, stream, ...rest } = params;
167
+ const result = {
168
+ ...rest,
169
+ model: model ?? this.defaultParams.model,
170
+ temperature: temperature === null ? undefined : (temperature ?? this.defaultParams.temperature),
171
+ top_p: topP === null ? undefined : (topP ?? this.defaultParams.topP),
172
+ max_tokens: maxTokens === null ? undefined : (maxTokens ?? this.defaultParams.maxTokens),
173
+ ...(typeof stream === 'boolean' && { stream }),
174
+ };
175
+ // OpenRouter-specific params not in OpenAI types — apply defaults
176
+ const extra = rest;
177
+ if (extra.top_k === undefined && this.defaultParams.topK !== undefined) {
178
+ result.top_k = this.defaultParams.topK;
179
+ }
180
+ if (extra.min_p === undefined && this.defaultParams.minP !== undefined) {
181
+ result.min_p = this.defaultParams.minP;
182
+ }
183
+ return result;
184
+ }
185
+ /**
186
+ * Dispatches a single chat completion call to the OpenRouter API via the
187
+ * provided `OpenAI` client. Logs the outbound request via `logInteraction`.
188
+ * For non-streaming calls, awaits the response and logs it before returning.
189
+ * For streaming calls, returns the `Stream` immediately; the caller is
190
+ * responsible for consuming and logging the stream (see `chatCompletionStream`).
191
+ *
192
+ * @param client - Initialized `OpenAI` client to use for the request.
193
+ * @param params - Fully-prepared API parameters (defaults already merged).
194
+ * @param context - Request context for correlated log entries.
195
+ * @returns `ChatCompletion` for non-streaming; `Stream<ChatCompletionChunk>` for streaming.
196
+ * @throws Propagates any error thrown by the OpenAI SDK.
197
+ */
198
+ async _openRouterChatCompletionLogic(client, params, context) {
199
+ this.logger.logInteraction('OpenRouterRequest', {
200
+ context,
201
+ request: params,
202
+ });
203
+ if (params.stream) {
204
+ return client.chat.completions.create(params);
205
+ }
206
+ else {
207
+ const response = await client.chat.completions.create(params);
208
+ this.logger.logInteraction('OpenRouterResponse', {
209
+ context,
210
+ response,
211
+ });
212
+ return response;
213
+ }
214
+ }
215
+ // --- PUBLIC METHODS (from ILlmProvider interface) ---
216
+ /**
217
+ * Sends a chat completion request to OpenRouter. Enforces rate limiting keyed
218
+ * on `context.auth?.clientId`, `context.tenantId`, or the global fallback key
219
+ * `'openrouter_global'`. Applies generation defaults via `_prepareApiParameters`
220
+ * before dispatching.
221
+ *
222
+ * Wraps execution in `ErrorHandler.tryCatch` for consistent error formatting and
223
+ * structured logging. Input params are sanitized before logging.
224
+ *
225
+ * @param params - Chat completion parameters (streaming or non-streaming).
226
+ * @param context - Request context for rate-limit keying, logging, and tracing.
227
+ * @returns `ChatCompletion` when `params.stream` is falsy; `Stream<ChatCompletionChunk>`
228
+ * when `params.stream` is `true`.
229
+ * @throws {McpError} `RateLimited` if the rate limit is exceeded.
230
+ * @throws {McpError} `ConfigurationError` if the OpenAI client cannot be initialized.
231
+ * @throws {McpError} `ServiceUnavailable` if the OpenRouter API call fails.
232
+ *
233
+ * @example
234
+ * ```ts
235
+ * const result = await provider.chatCompletion(
236
+ * { model: 'openai/gpt-4o', messages: [{ role: 'user', content: 'Hello' }] },
237
+ * ctx,
238
+ * ) as ChatCompletion;
239
+ * console.log(result.choices[0].message.content);
240
+ * ```
241
+ */
242
+ async chatCompletion(params, context) {
243
+ const operation = 'OpenRouterProvider.chatCompletion';
244
+ const sanitizedParams = sanitization.sanitizeForLogging(params);
245
+ return await ErrorHandler.tryCatch(async () => {
246
+ const rateLimitKey = context.auth?.clientId ?? context.tenantId ?? 'openrouter_global';
247
+ this.rateLimiter.check(rateLimitKey, context);
248
+ const finalApiParams = this._prepareApiParameters(params);
249
+ const client = await this.ensureClient();
250
+ return await this._openRouterChatCompletionLogic(client, finalApiParams, context);
251
+ }, { operation, context, input: sanitizedParams });
252
+ }
253
+ /**
254
+ * Sends a streaming chat completion request to OpenRouter and returns an async
255
+ * generator that yields `ChatCompletionChunk` objects as they arrive.
256
+ *
257
+ * Internally delegates to `chatCompletion` with `stream: true` forced, then
258
+ * wraps the resulting `Stream` in a generator that collects all chunks and logs
259
+ * the full response (via `logInteraction`) in the generator's `finally` block
260
+ * once the stream is exhausted or the consumer breaks out early.
261
+ *
262
+ * @param params - Chat completion parameters. `stream` is overridden to `true`.
263
+ * @param context - Request context for rate-limit keying, logging, and tracing.
264
+ * @returns An async iterable that yields `ChatCompletionChunk` objects.
265
+ * @throws {McpError} `RateLimited` if the rate limit is exceeded.
266
+ * @throws {McpError} `ConfigurationError` if the OpenAI client cannot be initialized.
267
+ * @throws {McpError} `ServiceUnavailable` if the OpenRouter API call fails.
268
+ *
269
+ * @example
270
+ * ```ts
271
+ * const stream = await provider.chatCompletionStream(
272
+ * { model: 'openai/gpt-4o', messages: [{ role: 'user', content: 'Hello' }] },
273
+ * ctx,
274
+ * );
275
+ * for await (const chunk of stream) {
276
+ * process.stdout.write(chunk.choices[0]?.delta?.content ?? '');
277
+ * }
278
+ * ```
279
+ */
280
+ async chatCompletionStream(params, context) {
281
+ const streamParams = { ...params, stream: true };
282
+ const responseStream = (await this.chatCompletion(streamParams, context));
283
+ const loggingStream = async function* () {
284
+ const chunks = [];
285
+ try {
286
+ for await (const chunk of responseStream) {
287
+ chunks.push(chunk);
288
+ yield chunk;
289
+ }
290
+ }
291
+ finally {
292
+ this.logger.logInteraction('OpenRouterResponse', {
293
+ context,
294
+ response: chunks,
295
+ streaming: true,
296
+ });
297
+ }
298
+ }.bind(this)();
299
+ return loggingStream;
300
+ }
301
+ }
302
+ //# sourceMappingURL=openrouter.provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openrouter.provider.js","sourceRoot":"","sources":["../../../../src/services/llm/providers/openrouter.provider.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,gDAAgD,CAAC;AAE9E,OAAO,EAAuB,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAEhG,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAEhE;;;GAGG;AACH,IAAI,OAA4C,CAAC;AAEjD;;;;;;;GAOG;AACH,KAAK,UAAU,SAAS;IACtB,OAAO,KAAK,MAAM,MAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE;QAC5C,MAAM,IAAI,QAAQ,CAChB,gBAAgB,CAAC,kBAAkB,EACnC,qEAAqE,CACtE,CAAC;IACJ,CAAC,CAAC,CAAC;IACH,OAAO,OAAO,CAAC,OAAO,CAAC;AACzB,CAAC;AA2BD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,OAAO,kBAAkB;IA8BnB;IACA;IACA;IA/BV,0EAA0E;IAClE,MAAM,CAAqB;IACnC;;;;OAIG;IACK,iBAAiB,CAA8B;IACvD,kFAAkF;IACjE,aAAa,CAO5B;IAEF;;;;;;;;;OASG;IACH,YACU,WAAwB,EACxB,MAAyB,EACzB,MAAyB;QAFzB,gBAAW,GAAX,WAAW,CAAa;QACxB,WAAM,GAAN,MAAM,CAAmB;QACzB,WAAM,GAAN,MAAM,CAAmB;QAEjC,MAAM,OAAO,GAAG,qBAAqB,CAAC,oBAAoB,CAAC;YACzD,SAAS,EAAE,gCAAgC;SAC5C,CAAC,CAAC;QAEH,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,gBAAgB,EAAE,CAAC;YAClC,IAAI,CAAC,MAAM,CAAC,KAAK,CACf,sEAAsE,EACtE,OAAO,CACR,CAAC;YACF,MAAM,IAAI,QAAQ,C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EAAE,MAAM,KAAK,IAAI,cAAc,EAAE,CAAC;oBACzC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;oBACnB,MAAM,KAAK,CAAC;gBACd,CAAC;YACH,CAAC;oBAAS,CAAC;gBACT,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,oBAAoB,EAAE;oBAC/C,OAAO;oBACP,QAAQ,EAAE,MAAM;oBAChB,SAAS,EAAE,IAAI;iBAChB,CAAC,CAAC;YACL,CAAC;QACH,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QAEf,OAAO,aAAa,CAAC;IACvB,CAAC;CACF"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @fileoverview Public type surface for the LLM service layer.
3
+ * Re-exports shared types from provider interfaces so consumers can import
4
+ * from a single stable path (`@/services/llm/types`) without coupling to
5
+ * internal provider modules.
6
+ * @module src/services/llm/types
7
+ */
8
+ /**
9
+ * Parameters accepted by the OpenRouter chat completion endpoint.
10
+ * Union of streaming and non-streaming variants from the OpenAI SDK
11
+ * (OpenRouter exposes an OpenAI-compatible API).
12
+ *
13
+ * Re-exported from `ILlmProvider` so callers import from one stable location.
14
+ */
15
+ export type { OpenRouterChatParams } from './core/ILlmProvider.js';
16
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/services/llm/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;;;GAMG;AACH,YAAY,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @fileoverview Public type surface for the LLM service layer.
3
+ * Re-exports shared types from provider interfaces so consumers can import
4
+ * from a single stable path (`@/services/llm/types`) without coupling to
5
+ * internal provider modules.
6
+ * @module src/services/llm/types
7
+ */
8
+ export {};
9
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/services/llm/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
@@ -0,0 +1,92 @@
1
+ /**
2
+ * @fileoverview Core interface definition for speech service providers.
3
+ * Provides the contract for Text-to-Speech (TTS) and Speech-to-Text (STT) operations.
4
+ * @module src/services/speech/core/ISpeechProvider
5
+ */
6
+ import type { SpeechToTextOptions, SpeechToTextResult, TextToSpeechOptions, TextToSpeechResult, Voice } from '../types.js';
7
+ /**
8
+ * Main interface for speech service providers.
9
+ * Providers may implement TTS, STT, or both. Check `supportsTTS` / `supportsSTT`
10
+ * before calling the corresponding method.
11
+ */
12
+ export interface ISpeechProvider {
13
+ /**
14
+ * Retrieve the list of voices available from this provider.
15
+ * Only meaningful for TTS providers; STT-only providers should throw.
16
+ *
17
+ * @returns Resolved array of available {@link Voice} objects.
18
+ * @throws {McpError} With `MethodNotFound` if the provider does not support TTS,
19
+ * or with `InternalError` / `ServiceUnavailable` if the API call fails.
20
+ */
21
+ getVoices(): Promise<Voice[]>;
22
+ /**
23
+ * Verify that the provider is reachable and properly configured.
24
+ * Implementations should perform a lightweight API call (e.g., listing models
25
+ * or voices) rather than a full synthesis/transcription round-trip.
26
+ *
27
+ * @returns `true` if the provider responded successfully, `false` otherwise.
28
+ * Never rejects — errors are caught and logged internally.
29
+ */
30
+ healthCheck(): Promise<boolean>;
31
+ /**
32
+ * Unique identifier for this provider implementation (e.g. `'elevenlabs'`, `'openai-whisper'`).
33
+ */
34
+ readonly name: string;
35
+ /**
36
+ * Transcribe audio data to text using this provider.
37
+ *
38
+ * @param options - Transcription options including audio data, format, language hint,
39
+ * model, temperature, and optional timestamp request.
40
+ * @returns Resolved {@link SpeechToTextResult} containing the transcript, detected language,
41
+ * duration, and optional word-level timestamps.
42
+ * @throws {McpError} With `MethodNotFound` if the provider does not support STT,
43
+ * `InvalidParams` for invalid or oversized audio, or `InternalError` on API failure.
44
+ */
45
+ speechToText(options: SpeechToTextOptions): Promise<SpeechToTextResult>;
46
+ /**
47
+ * `true` if this provider supports speech-to-text transcription.
48
+ * Check before calling {@link speechToText}.
49
+ */
50
+ readonly supportsSTT: boolean;
51
+ /**
52
+ * `true` if this provider supports text-to-speech synthesis.
53
+ * Check before calling {@link textToSpeech}.
54
+ */
55
+ readonly supportsTTS: boolean;
56
+ /**
57
+ * Synthesize speech audio from text using this provider.
58
+ *
59
+ * @param options - Synthesis options including the text, voice settings, output format,
60
+ * language, and model ID.
61
+ * @returns Resolved {@link TextToSpeechResult} containing audio data as a Buffer,
62
+ * character count, format, and provider metadata.
63
+ * @throws {McpError} With `MethodNotFound` if the provider does not support TTS,
64
+ * `InvalidParams` for empty or oversized text, or `InternalError` on API failure.
65
+ */
66
+ textToSpeech(options: TextToSpeechOptions): Promise<TextToSpeechResult>;
67
+ }
68
+ /**
69
+ * Type guard — returns `true` if the provider supports text-to-speech synthesis.
70
+ *
71
+ * @param provider - Any `ISpeechProvider` instance.
72
+ * @returns `true` when `provider.supportsTTS` is set, narrowing the type for callers.
73
+ *
74
+ * @example
75
+ * if (supportsTTS(provider)) {
76
+ * const result = await provider.textToSpeech({ text: 'Hello' });
77
+ * }
78
+ */
79
+ export declare function supportsTTS(provider: ISpeechProvider): provider is ISpeechProvider;
80
+ /**
81
+ * Type guard — returns `true` if the provider supports speech-to-text transcription.
82
+ *
83
+ * @param provider - Any `ISpeechProvider` instance.
84
+ * @returns `true` when `provider.supportsSTT` is set, narrowing the type for callers.
85
+ *
86
+ * @example
87
+ * if (supportsSTT(provider)) {
88
+ * const result = await provider.speechToText({ audio: buffer });
89
+ * }
90
+ */
91
+ export declare function supportsSTT(provider: ISpeechProvider): provider is ISpeechProvider;
92
+ //# sourceMappingURL=ISpeechProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ISpeechProvider.d.ts","sourceRoot":"","sources":["../../../../src/services/speech/core/ISpeechProvider.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,EACnB,kBAAkB,EAClB,KAAK,EACN,MAAM,aAAa,CAAC;AAErB;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B;;;;;;;OAOG;IACH,SAAS,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;IAE9B;;;;;;;OAOG;IACH,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IAEhC;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;;;;;;;;OASG;IACH,YAAY,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAExE;;;OAGG;IACH,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;IAE9B;;;OAGG;IACH,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;IAE9B;;;;;;;;;OASG;IACH,YAAY,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;CACzE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,eAAe,GAAG,QAAQ,IAAI,eAAe,CAElF;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,eAAe,GAAG,QAAQ,IAAI,eAAe,CAElF"}