@jsonstudio/llms 0.4.3 → 0.4.5

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 (542) hide show
  1. package/README.md +3 -1
  2. package/dist/bridge/routecodex-adapter.js +6 -3
  3. package/dist/config-unified/enhanced-path-resolver.js +14 -6
  4. package/dist/config-unified/unified-config.js +103 -59
  5. package/dist/conversion/codec-registry.js +15 -3
  6. package/dist/conversion/codecs/anthropic-openai-codec.d.ts +3 -13
  7. package/dist/conversion/codecs/anthropic-openai-codec.js +18 -473
  8. package/dist/conversion/codecs/gemini-openai-codec.js +91 -48
  9. package/dist/conversion/codecs/responses-openai-codec.js +9 -2
  10. package/dist/conversion/hub/format-adapters/anthropic-format-adapter.js +3 -0
  11. package/dist/conversion/hub/format-adapters/chat-format-adapter.js +3 -0
  12. package/dist/conversion/hub/format-adapters/gemini-format-adapter.js +3 -0
  13. package/dist/conversion/hub/format-adapters/responses-format-adapter.d.ts +2 -0
  14. package/dist/conversion/hub/format-adapters/responses-format-adapter.js +9 -0
  15. package/dist/conversion/hub/node-support.js +3 -1
  16. package/dist/conversion/hub/pipeline/hub-pipeline.js +41 -37
  17. package/dist/conversion/hub/process/chat-process.js +258 -41
  18. package/dist/conversion/hub/response/provider-response.js +9 -3
  19. package/dist/conversion/hub/response/response-mappers.js +1 -1
  20. package/dist/conversion/hub/response/response-runtime.js +109 -10
  21. package/dist/conversion/hub/semantic-mappers/anthropic-mapper.js +70 -156
  22. package/dist/conversion/hub/semantic-mappers/chat-mapper.js +63 -52
  23. package/dist/conversion/hub/semantic-mappers/gemini-mapper.js +76 -143
  24. package/dist/conversion/hub/semantic-mappers/responses-mapper.js +40 -160
  25. package/dist/conversion/hub/standardized-bridge.js +3 -0
  26. package/dist/conversion/hub/tool-governance/engine.d.ts +16 -0
  27. package/dist/conversion/hub/tool-governance/engine.js +266 -0
  28. package/dist/conversion/hub/tool-governance/index.d.ts +3 -0
  29. package/dist/conversion/hub/tool-governance/index.js +2 -0
  30. package/dist/conversion/hub/tool-governance/rules.d.ts +2 -0
  31. package/dist/conversion/hub/tool-governance/rules.js +76 -0
  32. package/dist/conversion/hub/tool-governance/types.d.ts +38 -0
  33. package/dist/conversion/index.d.ts +6 -0
  34. package/dist/conversion/index.js +6 -0
  35. package/dist/conversion/pipeline/codecs/v2/anthropic-openai-pipeline.d.ts +12 -0
  36. package/dist/conversion/pipeline/codecs/v2/anthropic-openai-pipeline.js +100 -0
  37. package/dist/conversion/pipeline/codecs/v2/openai-openai-pipeline.d.ts +15 -0
  38. package/dist/conversion/pipeline/codecs/v2/openai-openai-pipeline.js +174 -0
  39. package/dist/conversion/pipeline/codecs/v2/responses-openai-pipeline.d.ts +14 -0
  40. package/dist/conversion/pipeline/codecs/v2/responses-openai-pipeline.js +166 -0
  41. package/dist/conversion/pipeline/codecs/v2/shared/openai-chat-helpers.d.ts +13 -0
  42. package/dist/conversion/pipeline/codecs/v2/shared/openai-chat-helpers.js +66 -0
  43. package/dist/conversion/pipeline/hooks/adapter-context.d.ts +7 -0
  44. package/dist/conversion/pipeline/hooks/adapter-context.js +18 -0
  45. package/dist/conversion/pipeline/hooks/protocol-hooks.d.ts +67 -0
  46. package/dist/conversion/pipeline/hooks/protocol-hooks.js +1 -0
  47. package/dist/conversion/pipeline/index.d.ts +35 -0
  48. package/dist/conversion/pipeline/index.js +103 -0
  49. package/dist/conversion/pipeline/meta/meta-bag.d.ts +20 -0
  50. package/dist/conversion/pipeline/meta/meta-bag.js +81 -0
  51. package/dist/conversion/pipeline/schema/canonical-chat.d.ts +18 -0
  52. package/dist/conversion/pipeline/schema/canonical-chat.js +1 -0
  53. package/dist/conversion/pipeline/schema/index.d.ts +1 -0
  54. package/dist/conversion/pipeline/schema/index.js +1 -0
  55. package/dist/conversion/responses/responses-openai-bridge.d.ts +11 -58
  56. package/dist/conversion/responses/responses-openai-bridge.js +157 -1144
  57. package/dist/conversion/shared/anthropic-message-utils.d.ts +12 -0
  58. package/dist/conversion/shared/anthropic-message-utils.js +587 -0
  59. package/dist/conversion/shared/bridge-actions.d.ts +39 -0
  60. package/dist/conversion/shared/bridge-actions.js +709 -0
  61. package/dist/conversion/shared/{responses-conversation-store.d.ts → bridge-conversation-store.d.ts} +7 -7
  62. package/dist/conversion/shared/bridge-conversation-store.js +279 -0
  63. package/dist/conversion/shared/bridge-id-utils.js +42 -0
  64. package/dist/conversion/shared/bridge-instructions.d.ts +1 -0
  65. package/dist/conversion/shared/bridge-instructions.js +113 -0
  66. package/dist/conversion/shared/bridge-message-types.d.ts +39 -0
  67. package/dist/conversion/shared/bridge-message-types.js +1 -0
  68. package/dist/conversion/shared/bridge-message-utils.d.ts +22 -0
  69. package/dist/conversion/shared/bridge-message-utils.js +473 -0
  70. package/dist/conversion/shared/bridge-metadata.d.ts +1 -0
  71. package/dist/conversion/shared/bridge-metadata.js +1 -0
  72. package/dist/conversion/shared/bridge-policies.d.ts +18 -0
  73. package/dist/conversion/shared/bridge-policies.js +276 -0
  74. package/dist/conversion/shared/bridge-request-adapter.d.ts +28 -0
  75. package/dist/conversion/shared/bridge-request-adapter.js +430 -0
  76. package/dist/conversion/shared/chat-output-normalizer.d.ts +4 -0
  77. package/dist/conversion/shared/chat-output-normalizer.js +56 -0
  78. package/dist/conversion/shared/chat-request-filters.js +24 -1
  79. package/dist/conversion/shared/gemini-tool-utils.d.ts +5 -0
  80. package/dist/conversion/shared/gemini-tool-utils.js +130 -0
  81. package/dist/conversion/shared/metadata-passthrough.d.ts +11 -0
  82. package/dist/conversion/shared/metadata-passthrough.js +57 -0
  83. package/dist/conversion/shared/output-content-normalizer.d.ts +12 -0
  84. package/dist/conversion/shared/output-content-normalizer.js +119 -0
  85. package/dist/conversion/shared/reasoning-normalizer.d.ts +21 -0
  86. package/dist/conversion/shared/reasoning-normalizer.js +368 -0
  87. package/dist/conversion/shared/reasoning-tool-normalizer.d.ts +12 -0
  88. package/dist/conversion/shared/reasoning-tool-normalizer.js +132 -0
  89. package/dist/conversion/shared/reasoning-tool-parser.d.ts +10 -0
  90. package/dist/conversion/shared/reasoning-tool-parser.js +95 -0
  91. package/dist/conversion/shared/reasoning-utils.d.ts +2 -0
  92. package/dist/conversion/shared/reasoning-utils.js +42 -0
  93. package/dist/conversion/shared/responses-conversation-store.js +5 -11
  94. package/dist/conversion/shared/responses-message-utils.d.ts +15 -0
  95. package/dist/conversion/shared/responses-message-utils.js +206 -0
  96. package/dist/conversion/shared/responses-output-builder.d.ts +15 -0
  97. package/dist/conversion/shared/responses-output-builder.js +179 -0
  98. package/dist/conversion/shared/responses-output-utils.d.ts +7 -0
  99. package/dist/conversion/shared/responses-output-utils.js +108 -0
  100. package/dist/conversion/shared/responses-request-adapter.d.ts +3 -41
  101. package/dist/conversion/shared/responses-request-adapter.js +9 -40
  102. package/dist/conversion/shared/responses-response-utils.d.ts +3 -0
  103. package/dist/conversion/shared/responses-response-utils.js +209 -0
  104. package/dist/conversion/shared/responses-tool-utils.d.ts +12 -0
  105. package/dist/conversion/shared/responses-tool-utils.js +90 -0
  106. package/dist/conversion/shared/responses-types.d.ts +33 -0
  107. package/dist/conversion/shared/responses-types.js +1 -0
  108. package/dist/conversion/shared/tool-call-utils.d.ts +11 -0
  109. package/dist/conversion/shared/tool-call-utils.js +56 -0
  110. package/dist/conversion/shared/tool-mapping.d.ts +9 -0
  111. package/dist/conversion/shared/tool-mapping.js +124 -0
  112. package/dist/conversion/shared/tool-normalizers.d.ts +4 -0
  113. package/dist/conversion/shared/tool-normalizers.js +84 -0
  114. package/dist/router/virtual-router/bootstrap.js +18 -3
  115. package/dist/router/virtual-router/provider-registry.js +4 -2
  116. package/dist/router/virtual-router/types.d.ts +6 -0
  117. package/dist/sse/index.d.ts +38 -2
  118. package/dist/sse/index.js +27 -0
  119. package/dist/sse/json-to-sse/anthropic-json-to-sse-converter.d.ts +12 -9
  120. package/dist/sse/json-to-sse/anthropic-json-to-sse-converter.js +106 -73
  121. package/dist/sse/json-to-sse/chat-json-to-sse-converter.js +6 -2
  122. package/dist/sse/json-to-sse/gemini-json-to-sse-converter.d.ts +14 -0
  123. package/dist/sse/json-to-sse/gemini-json-to-sse-converter.js +99 -0
  124. package/dist/sse/json-to-sse/index.d.ts +2 -1
  125. package/dist/sse/json-to-sse/index.js +2 -0
  126. package/dist/sse/json-to-sse/sequencers/anthropic-sequencer.d.ts +13 -0
  127. package/dist/sse/json-to-sse/sequencers/anthropic-sequencer.js +150 -0
  128. package/dist/sse/json-to-sse/sequencers/chat-sequencer.d.ts +3 -1
  129. package/dist/sse/json-to-sse/sequencers/chat-sequencer.js +49 -3
  130. package/dist/sse/json-to-sse/sequencers/gemini-sequencer.d.ts +10 -0
  131. package/dist/sse/json-to-sse/sequencers/gemini-sequencer.js +95 -0
  132. package/dist/sse/json-to-sse/sequencers/responses-sequencer.js +31 -5
  133. package/dist/sse/registry/sse-codec-registry.d.ts +1 -1
  134. package/dist/sse/registry/sse-codec-registry.js +30 -1
  135. package/dist/sse/shared/reasoning-dispatcher.d.ts +10 -0
  136. package/dist/sse/shared/reasoning-dispatcher.js +25 -0
  137. package/dist/sse/shared/responses-output-normalizer.d.ts +12 -0
  138. package/dist/sse/shared/responses-output-normalizer.js +45 -0
  139. package/dist/sse/shared/serializers/anthropic-event-serializer.d.ts +2 -0
  140. package/dist/sse/shared/serializers/anthropic-event-serializer.js +9 -0
  141. package/dist/sse/shared/serializers/gemini-event-serializer.d.ts +2 -0
  142. package/dist/sse/shared/serializers/gemini-event-serializer.js +5 -0
  143. package/dist/sse/shared/serializers/index.d.ts +2 -0
  144. package/dist/sse/shared/serializers/index.js +2 -0
  145. package/dist/sse/shared/writer.d.ts +17 -1
  146. package/dist/sse/shared/writer.js +37 -1
  147. package/dist/sse/sse-to-json/anthropic-sse-to-json-converter.d.ts +9 -11
  148. package/dist/sse/sse-to-json/anthropic-sse-to-json-converter.js +92 -127
  149. package/dist/sse/sse-to-json/builders/anthropic-response-builder.d.ts +16 -0
  150. package/dist/sse/sse-to-json/builders/anthropic-response-builder.js +151 -0
  151. package/dist/sse/sse-to-json/builders/response-builder.d.ts +1 -1
  152. package/dist/sse/sse-to-json/builders/response-builder.js +29 -7
  153. package/dist/sse/sse-to-json/chat-sse-to-json-converter.d.ts +8 -0
  154. package/dist/sse/sse-to-json/chat-sse-to-json-converter.js +116 -26
  155. package/dist/sse/sse-to-json/gemini-sse-to-json-converter.d.ts +13 -0
  156. package/dist/sse/sse-to-json/gemini-sse-to-json-converter.js +160 -0
  157. package/dist/sse/sse-to-json/index.d.ts +2 -1
  158. package/dist/sse/sse-to-json/index.js +2 -0
  159. package/dist/sse/sse-to-json/parsers/sse-parser.js +73 -13
  160. package/dist/sse/sse-to-json/responses-sse-to-json-converter.d.ts +1 -0
  161. package/dist/sse/sse-to-json/responses-sse-to-json-converter.js +10 -8
  162. package/dist/sse/types/anthropic-types.d.ts +119 -36
  163. package/dist/sse/types/anthropic-types.js +8 -5
  164. package/dist/sse/types/chat-types.d.ts +19 -6
  165. package/dist/sse/types/chat-types.js +2 -1
  166. package/dist/sse/types/conversion-context.d.ts +14 -11
  167. package/dist/sse/types/core-interfaces.d.ts +7 -3
  168. package/dist/sse/types/gemini-types.d.ts +116 -0
  169. package/dist/sse/types/gemini-types.js +5 -0
  170. package/dist/sse/types/index.d.ts +5 -2
  171. package/dist/sse/types/index.js +2 -0
  172. package/dist/sse/types/responses-types.d.ts +20 -20
  173. package/dist/sse/types/sse-events.d.ts +4 -3
  174. package/dist/sse/types/stream-state.d.ts +34 -39
  175. package/dist/sse/types/utility-types.d.ts +47 -43
  176. package/dist/sse/types/utility-types.js +10 -13
  177. package/dist/tools/tool-registry.js +156 -98
  178. package/package.json +7 -7
  179. package/dist/api/index.d.ts +0 -10
  180. package/dist/api/index.js +0 -11
  181. package/dist/api/llmswitch-config.d.ts +0 -15
  182. package/dist/api/llmswitch-config.js +0 -415
  183. package/dist/api/llmswitch-types.d.ts +0 -412
  184. package/dist/api/llmswitch-types.js +0 -60
  185. package/dist/bridge/routecodex-adapter.d.ts +0 -74
  186. package/dist/config/index.d.ts +0 -3
  187. package/dist/config/index.js +0 -5
  188. package/dist/config-unified/enhanced-path-resolver.d.ts +0 -5
  189. package/dist/config-unified/unified-config.d.ts +0 -26
  190. package/dist/conversion/codec-registry.d.ts +0 -10
  191. package/dist/conversion/codecs/gemini-openai-codec.d.ts +0 -16
  192. package/dist/conversion/codecs/openai-openai-codec.d.ts +0 -12
  193. package/dist/conversion/codecs/responses-openai-codec.d.ts +0 -12
  194. package/dist/conversion/config/config-manager.d.ts +0 -212
  195. package/dist/conversion/conversion-v3/adapters/index.d.ts +0 -2
  196. package/dist/conversion/conversion-v3/adapters/index.js +0 -1
  197. package/dist/conversion/conversion-v3/adapters/v3-to-standard-adapter.d.ts +0 -38
  198. package/dist/conversion/conversion-v3/adapters/v3-to-standard-adapter.js +0 -55
  199. package/dist/conversion/conversion-v3/compatibility/compatibility-profiles.d.ts +0 -22
  200. package/dist/conversion/conversion-v3/compatibility/compatibility-profiles.js +0 -84
  201. package/dist/conversion/conversion-v3/compatibility/compatibility-stages.d.ts +0 -4
  202. package/dist/conversion/conversion-v3/compatibility/compatibility-stages.js +0 -285
  203. package/dist/conversion/conversion-v3/compatibility/index.d.ts +0 -3
  204. package/dist/conversion/conversion-v3/compatibility/index.js +0 -2
  205. package/dist/conversion/conversion-v3/config/default-configs.d.ts +0 -48
  206. package/dist/conversion/conversion-v3/config/default-configs.js +0 -1007
  207. package/dist/conversion/conversion-v3/config/index.d.ts +0 -5
  208. package/dist/conversion/conversion-v3/config/index.js +0 -5
  209. package/dist/conversion/conversion-v3/config/pipeline-config-manager.d.ts +0 -49
  210. package/dist/conversion/conversion-v3/config/pipeline-config-manager.js +0 -65
  211. package/dist/conversion/conversion-v3/index.d.ts +0 -11
  212. package/dist/conversion/conversion-v3/index.js +0 -17
  213. package/dist/conversion/conversion-v3/nodes/index.d.ts +0 -56
  214. package/dist/conversion/conversion-v3/nodes/index.js +0 -149
  215. package/dist/conversion/conversion-v3/nodes/input/anthropic-input-node.d.ts +0 -25
  216. package/dist/conversion/conversion-v3/nodes/input/anthropic-input-node.js +0 -56
  217. package/dist/conversion/conversion-v3/nodes/input/base-input-node.d.ts +0 -75
  218. package/dist/conversion/conversion-v3/nodes/input/base-input-node.js +0 -237
  219. package/dist/conversion/conversion-v3/nodes/input/chat-input-node.d.ts +0 -25
  220. package/dist/conversion/conversion-v3/nodes/input/chat-input-node.js +0 -56
  221. package/dist/conversion/conversion-v3/nodes/input/chat-shape-helpers.d.ts +0 -4
  222. package/dist/conversion/conversion-v3/nodes/input/chat-shape-helpers.js +0 -197
  223. package/dist/conversion/conversion-v3/nodes/input/gemini-input-node.d.ts +0 -16
  224. package/dist/conversion/conversion-v3/nodes/input/gemini-input-node.js +0 -125
  225. package/dist/conversion/conversion-v3/nodes/input/index.d.ts +0 -8
  226. package/dist/conversion/conversion-v3/nodes/input/index.js +0 -8
  227. package/dist/conversion/conversion-v3/nodes/input/input-decision.d.ts +0 -46
  228. package/dist/conversion/conversion-v3/nodes/input/input-decision.js +0 -125
  229. package/dist/conversion/conversion-v3/nodes/input/responses-input-node.d.ts +0 -20
  230. package/dist/conversion/conversion-v3/nodes/input/responses-input-node.js +0 -51
  231. package/dist/conversion/conversion-v3/nodes/output/anthropic-output-node.d.ts +0 -71
  232. package/dist/conversion/conversion-v3/nodes/output/anthropic-output-node.js +0 -320
  233. package/dist/conversion/conversion-v3/nodes/output/base-output-node.d.ts +0 -116
  234. package/dist/conversion/conversion-v3/nodes/output/base-output-node.js +0 -512
  235. package/dist/conversion/conversion-v3/nodes/output/index.d.ts +0 -7
  236. package/dist/conversion/conversion-v3/nodes/output/index.js +0 -7
  237. package/dist/conversion/conversion-v3/nodes/output/openai-output-node.d.ts +0 -71
  238. package/dist/conversion/conversion-v3/nodes/output/openai-output-node.js +0 -293
  239. package/dist/conversion/conversion-v3/nodes/output/output-decision.d.ts +0 -68
  240. package/dist/conversion/conversion-v3/nodes/output/output-decision.js +0 -161
  241. package/dist/conversion/conversion-v3/nodes/output/responses-output-node.d.ts +0 -64
  242. package/dist/conversion/conversion-v3/nodes/output/responses-output-node.js +0 -323
  243. package/dist/conversion/conversion-v3/nodes/process/base-process-node.d.ts +0 -72
  244. package/dist/conversion/conversion-v3/nodes/process/base-process-node.js +0 -246
  245. package/dist/conversion/conversion-v3/nodes/process/chat-process-node.d.ts +0 -135
  246. package/dist/conversion/conversion-v3/nodes/process/chat-process-node.js +0 -854
  247. package/dist/conversion/conversion-v3/nodes/process/compatibility-process-node.d.ts +0 -29
  248. package/dist/conversion/conversion-v3/nodes/process/compatibility-process-node.js +0 -181
  249. package/dist/conversion/conversion-v3/nodes/process/index.d.ts +0 -10
  250. package/dist/conversion/conversion-v3/nodes/process/index.js +0 -10
  251. package/dist/conversion/conversion-v3/nodes/process/passthrough-process-node.d.ts +0 -59
  252. package/dist/conversion/conversion-v3/nodes/process/passthrough-process-node.js +0 -243
  253. package/dist/conversion/conversion-v3/nodes/process/response-process-node.d.ts +0 -17
  254. package/dist/conversion/conversion-v3/nodes/process/response-process-node.js +0 -213
  255. package/dist/conversion/conversion-v3/nodes/process/tool-process-node.d.ts +0 -30
  256. package/dist/conversion/conversion-v3/nodes/process/tool-process-node.js +0 -360
  257. package/dist/conversion/conversion-v3/nodes/process/virtual-router-process-node.d.ts +0 -40
  258. package/dist/conversion/conversion-v3/nodes/process/virtual-router-process-node.js +0 -430
  259. package/dist/conversion/conversion-v3/nodes/response/anthropic-response-input-node.d.ts +0 -12
  260. package/dist/conversion/conversion-v3/nodes/response/anthropic-response-input-node.js +0 -129
  261. package/dist/conversion/conversion-v3/nodes/response/chat-to-responses-response-node.d.ts +0 -15
  262. package/dist/conversion/conversion-v3/nodes/response/chat-to-responses-response-node.js +0 -57
  263. package/dist/conversion/conversion-v3/nodes/response/index.d.ts +0 -4
  264. package/dist/conversion/conversion-v3/nodes/response/index.js +0 -4
  265. package/dist/conversion/conversion-v3/nodes/response/openai-response-input-node.d.ts +0 -15
  266. package/dist/conversion/conversion-v3/nodes/response/openai-response-input-node.js +0 -87
  267. package/dist/conversion/conversion-v3/nodes/response/response-utils.d.ts +0 -1
  268. package/dist/conversion/conversion-v3/nodes/response/response-utils.js +0 -1
  269. package/dist/conversion/conversion-v3/nodes/response/responses-response-input-node.d.ts +0 -12
  270. package/dist/conversion/conversion-v3/nodes/response/responses-response-input-node.js +0 -67
  271. package/dist/conversion/conversion-v3/nodes/sse/index.d.ts +0 -3
  272. package/dist/conversion/conversion-v3/nodes/sse/index.js +0 -3
  273. package/dist/conversion/conversion-v3/nodes/sse/sse-input-node.d.ts +0 -27
  274. package/dist/conversion/conversion-v3/nodes/sse/sse-input-node.js +0 -165
  275. package/dist/conversion/conversion-v3/nodes/sse/sse-output-node.d.ts +0 -19
  276. package/dist/conversion/conversion-v3/nodes/sse/sse-output-node.js +0 -267
  277. package/dist/conversion/conversion-v3/nodes/sse/sse-passthrough-node.d.ts +0 -18
  278. package/dist/conversion/conversion-v3/nodes/sse/sse-passthrough-node.js +0 -48
  279. package/dist/conversion/conversion-v3/pipelines/index.d.ts +0 -6
  280. package/dist/conversion/conversion-v3/pipelines/index.js +0 -6
  281. package/dist/conversion/conversion-v3/pipelines/super-pipeline.d.ts +0 -112
  282. package/dist/conversion/conversion-v3/pipelines/super-pipeline.js +0 -566
  283. package/dist/conversion/conversion-v3/response/provider-response-converter.d.ts +0 -28
  284. package/dist/conversion/conversion-v3/response/provider-response-converter.js +0 -249
  285. package/dist/conversion/conversion-v3/sse/index.d.ts +0 -140
  286. package/dist/conversion/conversion-v3/sse/index.js +0 -115
  287. package/dist/conversion/conversion-v3/sse/json-to-sse/anthropic-json-to-sse-converter.d.ts +0 -11
  288. package/dist/conversion/conversion-v3/sse/json-to-sse/anthropic-json-to-sse-converter.js +0 -79
  289. package/dist/conversion/conversion-v3/sse/json-to-sse/chat-json-to-sse-converter.d.ts +0 -79
  290. package/dist/conversion/conversion-v3/sse/json-to-sse/chat-json-to-sse-converter.js +0 -296
  291. package/dist/conversion/conversion-v3/sse/json-to-sse/event-generators/chat.d.ts +0 -55
  292. package/dist/conversion/conversion-v3/sse/json-to-sse/event-generators/chat.js +0 -233
  293. package/dist/conversion/conversion-v3/sse/json-to-sse/event-generators/responses.d.ts +0 -99
  294. package/dist/conversion/conversion-v3/sse/json-to-sse/event-generators/responses.js +0 -599
  295. package/dist/conversion/conversion-v3/sse/json-to-sse/index.d.ts +0 -6
  296. package/dist/conversion/conversion-v3/sse/json-to-sse/index.js +0 -7
  297. package/dist/conversion/conversion-v3/sse/json-to-sse/responses-json-to-sse-converter.d.ts +0 -79
  298. package/dist/conversion/conversion-v3/sse/json-to-sse/responses-json-to-sse-converter.js +0 -322
  299. package/dist/conversion/conversion-v3/sse/json-to-sse/sequencers/chat-sequencer.d.ts +0 -37
  300. package/dist/conversion/conversion-v3/sse/json-to-sse/sequencers/chat-sequencer.js +0 -218
  301. package/dist/conversion/conversion-v3/sse/json-to-sse/sequencers/responses-sequencer.d.ts +0 -40
  302. package/dist/conversion/conversion-v3/sse/json-to-sse/sequencers/responses-sequencer.js +0 -263
  303. package/dist/conversion/conversion-v3/sse/registry/sse-codec-registry.d.ts +0 -32
  304. package/dist/conversion/conversion-v3/sse/registry/sse-codec-registry.js +0 -106
  305. package/dist/conversion/conversion-v3/sse/shared/chat-serializer.d.ts +0 -4
  306. package/dist/conversion/conversion-v3/sse/shared/chat-serializer.js +0 -40
  307. package/dist/conversion/conversion-v3/sse/shared/constants.d.ts +0 -272
  308. package/dist/conversion/conversion-v3/sse/shared/constants.js +0 -321
  309. package/dist/conversion/conversion-v3/sse/shared/serializers/base-serializer.d.ts +0 -158
  310. package/dist/conversion/conversion-v3/sse/shared/serializers/base-serializer.js +0 -210
  311. package/dist/conversion/conversion-v3/sse/shared/serializers/chat-event-serializer.d.ts +0 -82
  312. package/dist/conversion/conversion-v3/sse/shared/serializers/chat-event-serializer.js +0 -275
  313. package/dist/conversion/conversion-v3/sse/shared/serializers/index.d.ts +0 -39
  314. package/dist/conversion/conversion-v3/sse/shared/serializers/index.js +0 -54
  315. package/dist/conversion/conversion-v3/sse/shared/serializers/responses-event-serializer.d.ts +0 -123
  316. package/dist/conversion/conversion-v3/sse/shared/serializers/responses-event-serializer.js +0 -356
  317. package/dist/conversion/conversion-v3/sse/shared/serializers/types.d.ts +0 -51
  318. package/dist/conversion/conversion-v3/sse/shared/serializers/types.js +0 -4
  319. package/dist/conversion/conversion-v3/sse/shared/utils.d.ts +0 -254
  320. package/dist/conversion/conversion-v3/sse/shared/utils.js +0 -543
  321. package/dist/conversion/conversion-v3/sse/shared/writer.d.ts +0 -111
  322. package/dist/conversion/conversion-v3/sse/shared/writer.js +0 -268
  323. package/dist/conversion/conversion-v3/sse/sse-to-json/anthropic-sse-to-json-converter.d.ts +0 -13
  324. package/dist/conversion/conversion-v3/sse/sse-to-json/anthropic-sse-to-json-converter.js +0 -139
  325. package/dist/conversion/conversion-v3/sse/sse-to-json/builders/response-builder.d.ts +0 -165
  326. package/dist/conversion/conversion-v3/sse/sse-to-json/builders/response-builder.js +0 -776
  327. package/dist/conversion/conversion-v3/sse/sse-to-json/chat-sse-to-json-converter.d.ts +0 -106
  328. package/dist/conversion/conversion-v3/sse/sse-to-json/chat-sse-to-json-converter.js +0 -540
  329. package/dist/conversion/conversion-v3/sse/sse-to-json/index.d.ts +0 -6
  330. package/dist/conversion/conversion-v3/sse/sse-to-json/index.js +0 -7
  331. package/dist/conversion/conversion-v3/sse/sse-to-json/parsers/sse-parser.d.ts +0 -73
  332. package/dist/conversion/conversion-v3/sse/sse-to-json/parsers/sse-parser.js +0 -332
  333. package/dist/conversion/conversion-v3/sse/sse-to-json/responses-sse-to-json-converter.d.ts +0 -59
  334. package/dist/conversion/conversion-v3/sse/sse-to-json/responses-sse-to-json-converter.js +0 -270
  335. package/dist/conversion/conversion-v3/sse/types/anthropic-types.d.ts +0 -87
  336. package/dist/conversion/conversion-v3/sse/types/anthropic-types.js +0 -5
  337. package/dist/conversion/conversion-v3/sse/types/chat-types.d.ts +0 -308
  338. package/dist/conversion/conversion-v3/sse/types/chat-types.js +0 -32
  339. package/dist/conversion/conversion-v3/sse/types/conversion-context.d.ts +0 -211
  340. package/dist/conversion/conversion-v3/sse/types/conversion-context.js +0 -20
  341. package/dist/conversion/conversion-v3/sse/types/core-interfaces.d.ts +0 -90
  342. package/dist/conversion/conversion-v3/sse/types/core-interfaces.js +0 -5
  343. package/dist/conversion/conversion-v3/sse/types/index.d.ts +0 -14
  344. package/dist/conversion/conversion-v3/sse/types/index.js +0 -7
  345. package/dist/conversion/conversion-v3/sse/types/responses-types.d.ts +0 -328
  346. package/dist/conversion/conversion-v3/sse/types/responses-types.js +0 -38
  347. package/dist/conversion/conversion-v3/sse/types/sse-events.d.ts +0 -180
  348. package/dist/conversion/conversion-v3/sse/types/sse-events.js +0 -150
  349. package/dist/conversion/conversion-v3/sse/types/stream-state.d.ts +0 -204
  350. package/dist/conversion/conversion-v3/sse/types/stream-state.js +0 -44
  351. package/dist/conversion/conversion-v3/sse/types/utility-types.d.ts +0 -230
  352. package/dist/conversion/conversion-v3/sse/types/utility-types.js +0 -49
  353. package/dist/conversion/conversion-v3/standards/context-adapter.d.ts +0 -146
  354. package/dist/conversion/conversion-v3/standards/context-adapter.js +0 -438
  355. package/dist/conversion/conversion-v3/standards/errors.d.ts +0 -38
  356. package/dist/conversion/conversion-v3/standards/errors.js +0 -27
  357. package/dist/conversion/conversion-v3/standards/index.d.ts +0 -15
  358. package/dist/conversion/conversion-v3/standards/index.js +0 -11
  359. package/dist/conversion/conversion-v3/standards/node-capabilities.d.ts +0 -123
  360. package/dist/conversion/conversion-v3/standards/node-capabilities.js +0 -330
  361. package/dist/conversion/conversion-v3/standards/pipeline-context.d.ts +0 -237
  362. package/dist/conversion/conversion-v3/standards/pipeline-context.js +0 -84
  363. package/dist/conversion/conversion-v3/standards/pipeline-node.d.ts +0 -196
  364. package/dist/conversion/conversion-v3/standards/pipeline-node.js +0 -316
  365. package/dist/conversion/conversion-v3/standards/snapshot-handles.d.ts +0 -24
  366. package/dist/conversion/conversion-v3/standards/snapshot-handles.js +0 -49
  367. package/dist/conversion/conversion-v3/types/config-types.d.ts +0 -242
  368. package/dist/conversion/conversion-v3/types/config-types.js +0 -13
  369. package/dist/conversion/conversion-v3/types/index.d.ts +0 -8
  370. package/dist/conversion/conversion-v3/types/index.js +0 -11
  371. package/dist/conversion/conversion-v3/types/node-types.d.ts +0 -211
  372. package/dist/conversion/conversion-v3/types/node-types.js +0 -20
  373. package/dist/conversion/conversion-v3/types/pipeline-types.d.ts +0 -246
  374. package/dist/conversion/conversion-v3/types/pipeline-types.js +0 -26
  375. package/dist/conversion/conversion-v3/types/request-types.d.ts +0 -293
  376. package/dist/conversion/conversion-v3/types/request-types.js +0 -26
  377. package/dist/conversion/conversion-v3/utils/provider-payload-sanitizer.d.ts +0 -10
  378. package/dist/conversion/conversion-v3/utils/provider-payload-sanitizer.js +0 -103
  379. package/dist/conversion/conversion-v3/validations/index.d.ts +0 -8
  380. package/dist/conversion/conversion-v3/validations/index.js +0 -7
  381. package/dist/conversion/conversion-v3/validations/node-graph-validator.d.ts +0 -116
  382. package/dist/conversion/conversion-v3/validations/node-graph-validator.js +0 -505
  383. package/dist/conversion/conversion-v3/validations/tool-governance-enforcer.d.ts +0 -139
  384. package/dist/conversion/conversion-v3/validations/tool-governance-enforcer.js +0 -338
  385. package/dist/conversion/hub/config/types.d.ts +0 -26
  386. package/dist/conversion/hub/core/detour-registry.d.ts +0 -9
  387. package/dist/conversion/hub/core/hub-context.d.ts +0 -21
  388. package/dist/conversion/hub/core/index.d.ts +0 -3
  389. package/dist/conversion/hub/core/stage-driver.d.ts +0 -30
  390. package/dist/conversion/hub/format-adapters/anthropic-format-adapter.d.ts +0 -16
  391. package/dist/conversion/hub/format-adapters/chat-format-adapter.d.ts +0 -17
  392. package/dist/conversion/hub/format-adapters/gemini-format-adapter.d.ts +0 -16
  393. package/dist/conversion/hub/format-adapters/index.d.ts +0 -21
  394. package/dist/conversion/hub/hub-feature.d.ts +0 -1
  395. package/dist/conversion/hub/node-support.d.ts +0 -19
  396. package/dist/conversion/hub/pipeline/hub-pipeline.d.ts +0 -68
  397. package/dist/conversion/hub/pipelines/inbound.d.ts +0 -22
  398. package/dist/conversion/hub/pipelines/outbound.d.ts +0 -22
  399. package/dist/conversion/hub/process/chat-process.d.ts +0 -13
  400. package/dist/conversion/hub/registry.d.ts +0 -28
  401. package/dist/conversion/hub/response/chat-response-utils.d.ts +0 -6
  402. package/dist/conversion/hub/response/provider-response.d.ts +0 -20
  403. package/dist/conversion/hub/response/response-mappers.d.ts +0 -19
  404. package/dist/conversion/hub/response/response-runtime.d.ts +0 -3
  405. package/dist/conversion/hub/semantic-mappers/anthropic-mapper.d.ts +0 -7
  406. package/dist/conversion/hub/semantic-mappers/chat-mapper.d.ts +0 -7
  407. package/dist/conversion/hub/semantic-mappers/gemini-mapper.d.ts +0 -7
  408. package/dist/conversion/hub/semantic-mappers/index.d.ts +0 -4
  409. package/dist/conversion/hub/semantic-mappers/responses-mapper.d.ts +0 -21
  410. package/dist/conversion/hub/snapshot-recorder.d.ts +0 -12
  411. package/dist/conversion/hub/standardized-bridge.d.ts +0 -12
  412. package/dist/conversion/hub/types/chat-envelope.d.ts +0 -67
  413. package/dist/conversion/hub/types/chat-schema.d.ts +0 -112
  414. package/dist/conversion/hub/types/errors.d.ts +0 -5
  415. package/dist/conversion/hub/types/format-envelope.d.ts +0 -7
  416. package/dist/conversion/hub/types/index.d.ts +0 -6
  417. package/dist/conversion/hub/types/json.d.ts +0 -9
  418. package/dist/conversion/hub/types/node.d.ts +0 -31
  419. package/dist/conversion/hub/types/standardized.d.ts +0 -94
  420. package/dist/conversion/schema-validator.d.ts +0 -7
  421. package/dist/conversion/shared/args-mapping.d.ts +0 -18
  422. package/dist/conversion/shared/chat-request-filters.d.ts +0 -9
  423. package/dist/conversion/shared/jsonish.d.ts +0 -3
  424. package/dist/conversion/shared/mcp-injection.d.ts +0 -2
  425. package/dist/conversion/shared/media.d.ts +0 -1
  426. package/dist/conversion/shared/openai-finalizer.d.ts +0 -9
  427. package/dist/conversion/shared/openai-message-normalize.d.ts +0 -1
  428. package/dist/conversion/shared/payload-budget.d.ts +0 -13
  429. package/dist/conversion/shared/reasoning-mapping.d.ts +0 -5
  430. package/dist/conversion/shared/responses-instructions.d.ts +0 -1
  431. package/dist/conversion/shared/responses-metadata.d.ts +0 -1
  432. package/dist/conversion/shared/snapshot-hooks.d.ts +0 -12
  433. package/dist/conversion/shared/streaming-text-extractor.d.ts +0 -26
  434. package/dist/conversion/shared/text-markup-normalizer.d.ts +0 -9
  435. package/dist/conversion/shared/tool-canonicalizer.d.ts +0 -2
  436. package/dist/conversion/shared/tool-filter-pipeline.d.ts +0 -17
  437. package/dist/conversion/shared/tool-governor.d.ts +0 -27
  438. package/dist/conversion/shared/tool-harvester.d.ts +0 -31
  439. package/dist/conversion/shared/tooling.d.ts +0 -26
  440. package/dist/conversion/types.d.ts +0 -33
  441. package/dist/core/index.d.ts +0 -6
  442. package/dist/core/index.js +0 -9
  443. package/dist/core/llmswitch-engine-v2.d.ts +0 -132
  444. package/dist/core/llmswitch-engine-v2.js +0 -649
  445. package/dist/core/llmswitch-factory-v2.d.ts +0 -123
  446. package/dist/core/llmswitch-factory-v2.js +0 -521
  447. package/dist/endpoints/base-endpoint-handler.d.ts +0 -128
  448. package/dist/endpoints/base-endpoint-handler.js +0 -545
  449. package/dist/endpoints/chat-endpoint-handler.d.ts +0 -115
  450. package/dist/endpoints/chat-endpoint-handler.js +0 -218
  451. package/dist/endpoints/endpoint-router.d.ts +0 -127
  452. package/dist/endpoints/endpoint-router.js +0 -438
  453. package/dist/endpoints/index.d.ts +0 -13
  454. package/dist/endpoints/index.js +0 -11
  455. package/dist/endpoints/messages-endpoint-handler.d.ts +0 -171
  456. package/dist/endpoints/messages-endpoint-handler.js +0 -238
  457. package/dist/endpoints/responses-endpoint-handler.d.ts +0 -147
  458. package/dist/endpoints/responses-endpoint-handler.js +0 -233
  459. package/dist/filters/builtin/add-fields-filter.d.ts +0 -8
  460. package/dist/filters/builtin/blacklist-filter.d.ts +0 -8
  461. package/dist/filters/builtin/whitelist-filter.d.ts +0 -8
  462. package/dist/filters/engine.d.ts +0 -16
  463. package/dist/filters/index.d.ts +0 -19
  464. package/dist/filters/special/request-streaming-to-nonstreaming.d.ts +0 -12
  465. package/dist/filters/special/request-tool-choice-policy.d.ts +0 -11
  466. package/dist/filters/special/request-tool-list-filter.d.ts +0 -11
  467. package/dist/filters/special/request-toolcalls-stringify.d.ts +0 -10
  468. package/dist/filters/special/request-tools-normalize.d.ts +0 -12
  469. package/dist/filters/special/response-finish-invariants.d.ts +0 -11
  470. package/dist/filters/special/response-openai-to-responses-bridge.d.ts +0 -13
  471. package/dist/filters/special/response-tool-arguments-blacklist.d.ts +0 -12
  472. package/dist/filters/special/response-tool-arguments-schema-converge.d.ts +0 -13
  473. package/dist/filters/special/response-tool-arguments-stringify.d.ts +0 -9
  474. package/dist/filters/special/response-tool-arguments-toon-decode.d.ts +0 -10
  475. package/dist/filters/special/response-tool-arguments-whitelist.d.ts +0 -11
  476. package/dist/filters/special/response-tool-text-canonicalize.d.ts +0 -10
  477. package/dist/filters/special/tool-filter-hooks.d.ts +0 -19
  478. package/dist/filters/special/tool-post-constraints.d.ts +0 -31
  479. package/dist/filters/types.d.ts +0 -68
  480. package/dist/filters/utils/fieldmap-loader.d.ts +0 -2
  481. package/dist/filters/utils/snapshot-writer.d.ts +0 -10
  482. package/dist/guidance/index.d.ts +0 -3
  483. package/dist/hooks/hooks-integration.d.ts +0 -161
  484. package/dist/hooks/hooks-integration.js +0 -519
  485. package/dist/hooks/index.d.ts +0 -10
  486. package/dist/hooks/index.js +0 -13
  487. package/dist/html-to-markdown.d.ts +0 -5
  488. package/dist/html-to-markdown.js +0 -66
  489. package/dist/http/sse-response.d.ts +0 -22
  490. package/dist/router/virtual-router/bootstrap.d.ts +0 -6
  491. package/dist/router/virtual-router/classifier.d.ts +0 -10
  492. package/dist/router/virtual-router/engine.d.ts +0 -35
  493. package/dist/router/virtual-router/error-center.d.ts +0 -10
  494. package/dist/router/virtual-router/features.d.ts +0 -3
  495. package/dist/router/virtual-router/health-manager.d.ts +0 -18
  496. package/dist/router/virtual-router/load-balancer.d.ts +0 -18
  497. package/dist/router/virtual-router/provider-registry.d.ts +0 -11
  498. package/dist/sse/json-to-sse/chat-json-to-sse-converter.d.ts +0 -79
  499. package/dist/sse/json-to-sse/event-generators/chat.d.ts +0 -55
  500. package/dist/sse/json-to-sse/event-generators/responses.d.ts +0 -99
  501. package/dist/sse/json-to-sse/responses-json-to-sse-converter.d.ts +0 -79
  502. package/dist/sse/json-to-sse/sequencers/responses-sequencer.d.ts +0 -40
  503. package/dist/sse/shared/chat-serializer.d.ts +0 -4
  504. package/dist/sse/shared/constants.d.ts +0 -272
  505. package/dist/sse/shared/serializers/base-serializer.d.ts +0 -158
  506. package/dist/sse/shared/serializers/chat-event-serializer.d.ts +0 -82
  507. package/dist/sse/shared/serializers/responses-event-serializer.d.ts +0 -123
  508. package/dist/sse/shared/serializers/types.d.ts +0 -51
  509. package/dist/sse/shared/utils.d.ts +0 -254
  510. package/dist/sse/sse-to-json/parsers/sse-parser.d.ts +0 -73
  511. package/dist/tools/proxy/anthropic-tool-proxy.d.ts +0 -19
  512. package/dist/tools/proxy/anthropic-tool-proxy.js +0 -57
  513. package/dist/tools/proxy/executors/web-fetch.d.ts +0 -6
  514. package/dist/tools/proxy/executors/web-fetch.js +0 -39
  515. package/dist/tools/proxy/registry.d.ts +0 -8
  516. package/dist/tools/proxy/registry.js +0 -14
  517. package/dist/tools/proxy/types.d.ts +0 -29
  518. package/dist/tools/tool-registry.d.ts +0 -8
  519. package/dist/tools/web-fetch-html.d.ts +0 -15
  520. package/dist/tools/web-fetch-html.js +0 -83
  521. package/dist/utils/conversion-adapter.d.ts +0 -65
  522. package/dist/utils/conversion-adapter.js +0 -183
  523. package/dist/utils/error-factory.d.ts +0 -88
  524. package/dist/utils/error-factory.js +0 -138
  525. package/dist/utils/error-utils.d.ts +0 -334
  526. package/dist/utils/error-utils.js +0 -782
  527. package/dist/utils/index.d.ts +0 -8
  528. package/dist/utils/index.js +0 -13
  529. package/dist/utils/performance-utils.d.ts +0 -205
  530. package/dist/utils/performance-utils.js +0 -440
  531. package/dist/utils/profile-mapper.d.ts +0 -32
  532. package/dist/utils/profile-mapper.js +0 -269
  533. package/dist/utils/request-processor.d.ts +0 -52
  534. package/dist/utils/request-processor.js +0 -210
  535. package/dist/utils/request-utils.d.ts +0 -117
  536. package/dist/utils/request-utils.js +0 -333
  537. package/dist/utils/response-utils.d.ts +0 -127
  538. package/dist/utils/response-utils.js +0 -516
  539. package/dist/utils/token-counter.d.ts +0 -89
  540. package/dist/utils/token-counter.js +0 -541
  541. /package/dist/{tools/proxy → conversion/hub/tool-governance}/types.js +0 -0
  542. /package/dist/conversion/shared/{responses-id-utils.d.ts → bridge-id-utils.d.ts} +0 -0
@@ -0,0 +1,174 @@
1
+ import { ProtocolConversionPipeline } from '../../index.js';
2
+ import { buildAdapterContextFromPipeline } from '../../hooks/adapter-context.js';
3
+ import { chatEnvelopeToStandardized } from '../../../hub/standardized-bridge.js';
4
+ import { ChatFormatAdapter } from '../../../hub/format-adapters/chat-format-adapter.js';
5
+ import { ChatSemanticMapper } from '../../../hub/semantic-mappers/chat-mapper.js';
6
+ import { runStandardChatRequestFilters } from '../../../index.js';
7
+ import { canonicalizeOpenAIChatResponse, convertStandardizedToOpenAIChat as convertCanonicalToOpenAIChat, DEFAULT_OPENAI_ENDPOINT, OPENAI_PROTOCOL } from './shared/openai-chat-helpers.js';
8
+ function assertJsonObject(value, stage) {
9
+ if (!value || typeof value !== 'object' || Array.isArray(value)) {
10
+ throw new Error(`OpenAI pipeline codec requires JSON payload at ${stage}`);
11
+ }
12
+ return value;
13
+ }
14
+ function restoreToolCallIndexes(targetMessages, sourceMessages) {
15
+ if (!Array.isArray(targetMessages) || !Array.isArray(sourceMessages)) {
16
+ return;
17
+ }
18
+ const sourceIndexMap = new Map();
19
+ for (const message of sourceMessages) {
20
+ if (!message || typeof message !== 'object')
21
+ continue;
22
+ const toolCalls = message.tool_calls;
23
+ if (!Array.isArray(toolCalls))
24
+ continue;
25
+ toolCalls.forEach((toolCall) => {
26
+ if (!toolCall || typeof toolCall !== 'object')
27
+ return;
28
+ const id = typeof toolCall.id === 'string'
29
+ ? String(toolCall.id)
30
+ : undefined;
31
+ if (!id || sourceIndexMap.has(id))
32
+ return;
33
+ const idxValue = toolCall.index;
34
+ if (typeof idxValue !== 'number')
35
+ return;
36
+ sourceIndexMap.set(id, idxValue);
37
+ });
38
+ }
39
+ for (const message of targetMessages) {
40
+ if (!message || typeof message !== 'object')
41
+ continue;
42
+ const toolCalls = message.tool_calls;
43
+ if (!Array.isArray(toolCalls))
44
+ continue;
45
+ toolCalls.forEach((toolCall) => {
46
+ if (!toolCall || typeof toolCall !== 'object')
47
+ return;
48
+ const id = typeof toolCall.id === 'string'
49
+ ? String(toolCall.id)
50
+ : undefined;
51
+ if (!id)
52
+ return;
53
+ const sourceIndex = sourceIndexMap.get(id);
54
+ if (sourceIndex === undefined)
55
+ return;
56
+ toolCall.index = sourceIndex;
57
+ });
58
+ }
59
+ }
60
+ function createOpenAIHooks() {
61
+ const formatAdapter = new ChatFormatAdapter();
62
+ const semanticMapper = new ChatSemanticMapper();
63
+ return {
64
+ id: 'openai-openai-v2',
65
+ protocol: OPENAI_PROTOCOL,
66
+ inbound: {
67
+ parse: async ({ wire, context }) => {
68
+ const adapterContext = buildAdapterContextFromPipeline(context, {
69
+ defaultEntryEndpoint: DEFAULT_OPENAI_ENDPOINT,
70
+ overrideProtocol: OPENAI_PROTOCOL
71
+ });
72
+ const formatEnvelope = await formatAdapter.parseRequest(wire, adapterContext);
73
+ const chatEnvelope = await semanticMapper.toChat(formatEnvelope, adapterContext);
74
+ const canonical = chatEnvelopeToStandardized(chatEnvelope, {
75
+ adapterContext,
76
+ endpoint: adapterContext.entryEndpoint ?? DEFAULT_OPENAI_ENDPOINT,
77
+ requestId: adapterContext.requestId
78
+ });
79
+ return { canonical };
80
+ }
81
+ },
82
+ outbound: {
83
+ serialize: async ({ canonical }) => {
84
+ return { payload: assertJsonObject(canonical, 'openai_outbound_serialize') };
85
+ }
86
+ }
87
+ };
88
+ }
89
+ function buildPipelineContext(profile, context) {
90
+ return {
91
+ requestId: context.requestId,
92
+ entryEndpoint: context.entryEndpoint ?? context.endpoint ?? DEFAULT_OPENAI_ENDPOINT,
93
+ providerProtocol: profile.incomingProtocol ?? context.targetProtocol ?? OPENAI_PROTOCOL,
94
+ targetProtocol: profile.outgoingProtocol ?? context.targetProtocol ?? OPENAI_PROTOCOL,
95
+ profileId: profile.id,
96
+ stream: context.stream,
97
+ metadata: context.metadata
98
+ };
99
+ }
100
+ export class OpenAIOpenAIPipelineCodec {
101
+ id = 'openai-openai-v2';
102
+ pipeline;
103
+ requestMetaStore = new Map();
104
+ initialized = false;
105
+ constructor() {
106
+ this.pipeline = new ProtocolConversionPipeline(createOpenAIHooks());
107
+ }
108
+ async initialize() {
109
+ this.initialized = true;
110
+ }
111
+ ensureInitialized() {
112
+ if (!this.initialized) {
113
+ throw new Error('OpenAIOpenAIPipelineCodec must be initialized before use');
114
+ }
115
+ }
116
+ stashMeta(requestId, bag) {
117
+ this.requestMetaStore.set(requestId, bag.snapshot());
118
+ }
119
+ consumeMeta(requestId) {
120
+ const stored = this.requestMetaStore.get(requestId);
121
+ if (stored) {
122
+ this.requestMetaStore.delete(requestId);
123
+ return stored;
124
+ }
125
+ return undefined;
126
+ }
127
+ async convertRequest(payload, profile, context) {
128
+ this.ensureInitialized();
129
+ const inboundContext = buildPipelineContext(profile, context);
130
+ const requestId = context.requestId ?? inboundContext.requestId ?? `req_${Date.now()}`;
131
+ inboundContext.requestId = requestId;
132
+ const inboundPayload = assertJsonObject(payload, 'openai_inbound_request');
133
+ const inboundOptions = {
134
+ payload: inboundPayload,
135
+ context: inboundContext
136
+ };
137
+ const inbound = await this.pipeline.convertInbound(inboundOptions);
138
+ this.stashMeta(requestId, inbound.meta);
139
+ const openaiPayload = await convertCanonicalToOpenAIChat(inbound.canonical, inbound.context);
140
+ if (!Array.isArray(openaiPayload.tools) && Array.isArray(inboundPayload.tools)) {
141
+ openaiPayload.tools = inboundPayload.tools;
142
+ }
143
+ if (openaiPayload.tool_choice === undefined &&
144
+ inboundPayload.tool_choice !== undefined) {
145
+ openaiPayload.tool_choice = inboundPayload.tool_choice;
146
+ }
147
+ const filterContext = {
148
+ ...context,
149
+ requestId,
150
+ entryEndpoint: context.entryEndpoint ?? DEFAULT_OPENAI_ENDPOINT,
151
+ endpoint: context.endpoint ?? DEFAULT_OPENAI_ENDPOINT
152
+ };
153
+ const filtered = await runStandardChatRequestFilters(openaiPayload, profile, filterContext);
154
+ if (filtered && typeof filtered === 'object') {
155
+ restoreToolCallIndexes(filtered.messages, inboundPayload.messages);
156
+ }
157
+ return filtered;
158
+ }
159
+ async convertResponse(payload, profile, context) {
160
+ this.ensureInitialized();
161
+ const pipelineContext = buildPipelineContext(profile, context);
162
+ const requestId = context.requestId ?? pipelineContext.requestId ?? `req_${Date.now()}`;
163
+ pipelineContext.requestId = requestId;
164
+ const storedMeta = this.consumeMeta(requestId);
165
+ const sanitized = await canonicalizeOpenAIChatResponse(assertJsonObject(payload, 'openai_chat_response'), context);
166
+ const outboundOptions = {
167
+ canonical: sanitized,
168
+ context: pipelineContext,
169
+ meta: storedMeta
170
+ };
171
+ const outbound = await this.pipeline.convertOutbound(outboundOptions);
172
+ return outbound.payload;
173
+ }
174
+ }
@@ -0,0 +1,14 @@
1
+ import type { ConversionCodec, ConversionContext, ConversionProfile } from '../../../types.js';
2
+ import type { JsonObject } from '../../../hub/types/json.js';
3
+ export declare class ResponsesOpenAIPipelineCodec implements ConversionCodec {
4
+ readonly id = "responses-openai-v2";
5
+ private readonly pipeline;
6
+ private readonly requestMetaStore;
7
+ private initialized;
8
+ constructor();
9
+ initialize(): Promise<void>;
10
+ private ensureInitialized;
11
+ private stashMeta;
12
+ convertRequest(payload: unknown, profile: ConversionProfile, context: ConversionContext): Promise<JsonObject>;
13
+ convertResponse(payload: unknown, profile: ConversionProfile, context: ConversionContext): Promise<JsonObject>;
14
+ }
@@ -0,0 +1,166 @@
1
+ import { ProtocolConversionPipeline } from '../../index.js';
2
+ import { chatEnvelopeToStandardized } from '../../../hub/standardized-bridge.js';
3
+ import { ResponsesFormatAdapter } from '../../../hub/format-adapters/responses-format-adapter.js';
4
+ import { ResponsesSemanticMapper } from '../../../hub/semantic-mappers/responses-mapper.js';
5
+ import { captureResponsesContext, buildChatRequestFromResponses, buildResponsesPayloadFromChat } from '../../../responses/responses-openai-bridge.js';
6
+ import { buildAdapterContextFromPipeline } from '../../hooks/adapter-context.js';
7
+ import { runStandardChatRequestFilters } from '../../../index.js';
8
+ import { canonicalizeOpenAIChatResponse, convertStandardizedToOpenAIChat as convertCanonicalToOpenAIChat, OPENAI_PROTOCOL } from './shared/openai-chat-helpers.js';
9
+ const DEFAULT_RESPONSES_ENDPOINT = '/v1/responses';
10
+ const RESPONSES_PROTOCOL = 'openai-responses';
11
+ function assertJsonObject(value, stage) {
12
+ if (!value || typeof value !== 'object' || Array.isArray(value)) {
13
+ throw new Error(`Responses pipeline codec requires JSON payload at ${stage}`);
14
+ }
15
+ return value;
16
+ }
17
+ function cloneResponsesContext(context) {
18
+ try {
19
+ return JSON.parse(JSON.stringify(context ?? {}));
20
+ }
21
+ catch {
22
+ return {};
23
+ }
24
+ }
25
+ function restoreResponsesContext(value) {
26
+ if (!value || typeof value !== 'object') {
27
+ return undefined;
28
+ }
29
+ return value;
30
+ }
31
+ function captureToolResults(payload) {
32
+ const results = [];
33
+ const inputArr = Array.isArray(payload?.input) ? payload.input : [];
34
+ for (const it of inputArr) {
35
+ if (!it || typeof it !== 'object')
36
+ continue;
37
+ const t = String(it.type || '').toLowerCase();
38
+ if (t === 'tool_result' || t === 'tool_message' || t === 'function_call_output') {
39
+ const tool_call_id = it.tool_call_id || it.call_id || it.tool_use_id;
40
+ let output = undefined;
41
+ const rawOut = it.output;
42
+ if (typeof rawOut === 'string')
43
+ output = rawOut;
44
+ else if (rawOut && typeof rawOut === 'object') {
45
+ try {
46
+ output = JSON.stringify(rawOut);
47
+ }
48
+ catch { /* ignore */ }
49
+ }
50
+ results.push({ tool_call_id, output });
51
+ }
52
+ }
53
+ return results;
54
+ }
55
+ function createResponsesHooks() {
56
+ const formatAdapter = new ResponsesFormatAdapter();
57
+ const semanticMapper = new ResponsesSemanticMapper();
58
+ return {
59
+ id: 'responses-openai-v2',
60
+ protocol: RESPONSES_PROTOCOL,
61
+ inbound: {
62
+ parse: async ({ wire, context, meta }) => {
63
+ const adapterContext = buildAdapterContextFromPipeline(context, {
64
+ defaultEntryEndpoint: DEFAULT_RESPONSES_ENDPOINT,
65
+ overrideProtocol: RESPONSES_PROTOCOL
66
+ });
67
+ const formatEnvelope = await formatAdapter.parseRequest(wire, adapterContext);
68
+ const chatEnvelope = await semanticMapper.toChat(formatEnvelope, adapterContext);
69
+ const canonical = chatEnvelopeToStandardized(chatEnvelope, {
70
+ adapterContext,
71
+ endpoint: adapterContext.entryEndpoint,
72
+ requestId: adapterContext.requestId
73
+ });
74
+ // Capture Responses-specific context for outbound mapping parity
75
+ const responsesContext = captureResponsesContext(wire, { route: { requestId: adapterContext.requestId } });
76
+ const built = buildChatRequestFromResponses(wire, responsesContext);
77
+ if (built.toolsNormalized) {
78
+ responsesContext.toolsNormalized = built.toolsNormalized;
79
+ }
80
+ const captured = captureToolResults(wire);
81
+ if (captured.length) {
82
+ responsesContext.__captured_tool_results = captured;
83
+ }
84
+ meta.set('responsesContext', cloneResponsesContext(responsesContext));
85
+ return { canonical };
86
+ }
87
+ },
88
+ outbound: {
89
+ serialize: async ({ canonical, meta }) => {
90
+ const stored = meta.consume('responsesContext');
91
+ const responsesContext = restoreResponsesContext(stored);
92
+ const payload = buildResponsesPayloadFromChat(canonical, responsesContext);
93
+ return { payload: assertJsonObject(payload, 'responses_outbound_serialize') };
94
+ }
95
+ }
96
+ };
97
+ }
98
+ function buildPipelineContext(profile, context) {
99
+ return {
100
+ requestId: context.requestId,
101
+ entryEndpoint: context.entryEndpoint ?? context.endpoint ?? DEFAULT_RESPONSES_ENDPOINT,
102
+ providerProtocol: profile.incomingProtocol ?? RESPONSES_PROTOCOL,
103
+ targetProtocol: profile.outgoingProtocol ?? context.targetProtocol ?? OPENAI_PROTOCOL,
104
+ profileId: profile.id,
105
+ stream: context.stream,
106
+ metadata: context.metadata
107
+ };
108
+ }
109
+ export class ResponsesOpenAIPipelineCodec {
110
+ id = 'responses-openai-v2';
111
+ pipeline;
112
+ requestMetaStore = new Map();
113
+ initialized = false;
114
+ constructor() {
115
+ this.pipeline = new ProtocolConversionPipeline(createResponsesHooks());
116
+ }
117
+ async initialize() {
118
+ this.initialized = true;
119
+ }
120
+ ensureInitialized() {
121
+ if (!this.initialized) {
122
+ throw new Error('ResponsesOpenAIPipelineCodec must be initialized before use');
123
+ }
124
+ }
125
+ stashMeta(requestId, bag) {
126
+ this.requestMetaStore.set(requestId, bag.snapshot());
127
+ }
128
+ async convertRequest(payload, profile, context) {
129
+ this.ensureInitialized();
130
+ const inboundContext = buildPipelineContext(profile, context);
131
+ const requestId = context.requestId ?? inboundContext.requestId ?? `req_${Date.now()}`;
132
+ inboundContext.requestId = requestId;
133
+ const inboundOptions = {
134
+ payload: assertJsonObject(payload, 'responses_inbound_request'),
135
+ context: inboundContext
136
+ };
137
+ const inbound = await this.pipeline.convertInbound(inboundOptions);
138
+ this.stashMeta(requestId, inbound.meta);
139
+ const openaiPayload = await convertCanonicalToOpenAIChat(inbound.canonical, inbound.context);
140
+ const filterContext = {
141
+ ...context,
142
+ requestId,
143
+ entryEndpoint: context.entryEndpoint ?? DEFAULT_RESPONSES_ENDPOINT,
144
+ endpoint: context.endpoint ?? DEFAULT_RESPONSES_ENDPOINT
145
+ };
146
+ return runStandardChatRequestFilters(openaiPayload, profile, filterContext);
147
+ }
148
+ async convertResponse(payload, profile, context) {
149
+ this.ensureInitialized();
150
+ const pipelineContext = buildPipelineContext(profile, context);
151
+ const requestId = context.requestId ?? pipelineContext.requestId ?? `req_${Date.now()}`;
152
+ pipelineContext.requestId = requestId;
153
+ const storedMeta = this.requestMetaStore.get(requestId);
154
+ if (storedMeta) {
155
+ this.requestMetaStore.delete(requestId);
156
+ }
157
+ const sanitized = await canonicalizeOpenAIChatResponse(assertJsonObject(payload, 'responses_openai_response'), context);
158
+ const outboundOptions = {
159
+ canonical: sanitized,
160
+ context: pipelineContext,
161
+ meta: storedMeta
162
+ };
163
+ const outbound = await this.pipeline.convertOutbound(outboundOptions);
164
+ return outbound.payload;
165
+ }
166
+ }
@@ -0,0 +1,13 @@
1
+ import type { JsonObject } from '../../../../hub/types/json.js';
2
+ import type { ConversionContext } from '../../../../types.js';
3
+ import type { CanonicalChatRequest } from '../../../schema/index.js';
4
+ import type { ProtocolPipelineContext } from '../../../hooks/protocol-hooks.js';
5
+ export declare const DEFAULT_OPENAI_ENDPOINT = "/v1/chat/completions";
6
+ export declare const OPENAI_PROTOCOL = "openai-chat";
7
+ export declare function convertStandardizedToOpenAIChat(standardized: CanonicalChatRequest, context: ProtocolPipelineContext, options?: {
8
+ defaultEndpoint?: string;
9
+ }): Promise<JsonObject>;
10
+ export declare function canonicalizeOpenAIChatResponse(payload: JsonObject, context: ConversionContext, options?: {
11
+ defaultEndpoint?: string;
12
+ profile?: string;
13
+ }): Promise<JsonObject>;
@@ -0,0 +1,66 @@
1
+ import { standardizedToChatEnvelope } from '../../../../hub/standardized-bridge.js';
2
+ import { buildAdapterContextFromPipeline } from '../../../hooks/adapter-context.js';
3
+ import { ChatFormatAdapter } from '../../../../hub/format-adapters/chat-format-adapter.js';
4
+ import { ChatSemanticMapper } from '../../../../hub/semantic-mappers/chat-mapper.js';
5
+ import { FilterEngine, ResponseToolTextCanonicalizeFilter, ResponseToolArgumentsStringifyFilter, ResponseFinishInvariantsFilter } from '../../../../../filters/index.js';
6
+ import { normalizeChatResponseReasoningTools } from '../../../../shared/reasoning-tool-normalizer.js';
7
+ export const DEFAULT_OPENAI_ENDPOINT = '/v1/chat/completions';
8
+ export const OPENAI_PROTOCOL = 'openai-chat';
9
+ const sharedChatFormatAdapter = new ChatFormatAdapter();
10
+ const sharedChatSemanticMapper = new ChatSemanticMapper();
11
+ function ensureJsonObject(value, stage) {
12
+ if (!value || typeof value !== 'object' || Array.isArray(value)) {
13
+ throw new Error(`OpenAI chat helper requires JSON object payload at ${stage}`);
14
+ }
15
+ return value;
16
+ }
17
+ export async function convertStandardizedToOpenAIChat(standardized, context, options) {
18
+ const adapterContext = buildAdapterContextFromPipeline(context, {
19
+ defaultEntryEndpoint: options?.defaultEndpoint ?? DEFAULT_OPENAI_ENDPOINT,
20
+ overrideProtocol: OPENAI_PROTOCOL
21
+ });
22
+ const chatEnvelope = standardizedToChatEnvelope(standardized, { adapterContext });
23
+ const formatEnvelope = await sharedChatSemanticMapper.fromChat(chatEnvelope, adapterContext);
24
+ const payload = await sharedChatFormatAdapter.buildRequest(formatEnvelope, adapterContext);
25
+ return ensureJsonObject(payload, 'openai_request_build');
26
+ }
27
+ export async function canonicalizeOpenAIChatResponse(payload, context, options) {
28
+ const dto = {
29
+ data: payload,
30
+ metadata: {
31
+ requestId: context.requestId ?? `req_${Date.now()}`,
32
+ pipelineId: context.metadata?.pipelineId ?? 'conversion-router',
33
+ processingTime: 0,
34
+ stages: []
35
+ }
36
+ };
37
+ const filterContext = {
38
+ requestId: dto.metadata.requestId,
39
+ model: typeof payload.model === 'string' ? payload.model : undefined,
40
+ endpoint: context.entryEndpoint ?? context.endpoint ?? options?.defaultEndpoint ?? DEFAULT_OPENAI_ENDPOINT,
41
+ profile: options?.profile ?? OPENAI_PROTOCOL,
42
+ debug: { emit: () => { } }
43
+ };
44
+ const engine = new FilterEngine();
45
+ engine.registerFilter(new ResponseToolTextCanonicalizeFilter());
46
+ try {
47
+ const { ResponseToolArgumentsToonDecodeFilter } = await import('../../../../../filters/index.js');
48
+ engine.registerFilter(new ResponseToolArgumentsToonDecodeFilter());
49
+ }
50
+ catch {
51
+ // optional decode filter
52
+ }
53
+ engine.registerFilter(new ResponseToolArgumentsStringifyFilter());
54
+ engine.registerFilter(new ResponseFinishInvariantsFilter());
55
+ const stage1 = await engine.run('response_pre', dto.data, filterContext);
56
+ const stage2 = await engine.run('response_map', stage1, filterContext);
57
+ const stage3 = await engine.run('response_post', stage2, filterContext);
58
+ const normalized = ensureJsonObject(stage3, 'openai_response_filters');
59
+ try {
60
+ normalizeChatResponseReasoningTools(normalized, { idPrefixBase: 'reasoning_choice' });
61
+ }
62
+ catch {
63
+ // reasoning normalization best-effort
64
+ }
65
+ return normalized;
66
+ }
@@ -0,0 +1,7 @@
1
+ import type { AdapterContext } from '../../hub/types/chat-envelope.js';
2
+ import type { ProtocolPipelineContext } from './protocol-hooks.js';
3
+ export interface AdapterContextOptions {
4
+ defaultEntryEndpoint?: string;
5
+ overrideProtocol?: string;
6
+ }
7
+ export declare function buildAdapterContextFromPipeline(context: ProtocolPipelineContext, options?: AdapterContextOptions): AdapterContext;
@@ -0,0 +1,18 @@
1
+ export function buildAdapterContextFromPipeline(context, options) {
2
+ const requestId = context.requestId ?? `req_${Date.now()}`;
3
+ const entryEndpoint = options?.defaultEntryEndpoint ??
4
+ context.entryEndpoint ??
5
+ '/v1/chat/completions';
6
+ const providerProtocol = options?.overrideProtocol ??
7
+ context.providerProtocol ??
8
+ context.targetProtocol ??
9
+ 'openai-chat';
10
+ const streamingHint = context.stream === true ? 'force' : context.stream === false ? 'disable' : 'auto';
11
+ return {
12
+ requestId,
13
+ entryEndpoint,
14
+ providerProtocol,
15
+ profileId: context.profileId,
16
+ streamingHint
17
+ };
18
+ }
@@ -0,0 +1,67 @@
1
+ import type { JsonObject } from '../../hub/types/json.js';
2
+ import type { CanonicalChatRequest, CanonicalChatResponse } from '../schema/index.js';
3
+ import type { ConversionMetaBag, ConversionMetaRecord } from '../meta/meta-bag.js';
4
+ export interface ProtocolPipelineContext {
5
+ requestId?: string;
6
+ entryEndpoint?: string;
7
+ profileId?: string;
8
+ providerProtocol?: string;
9
+ targetProtocol?: string;
10
+ stream?: boolean;
11
+ metadata?: Record<string, unknown>;
12
+ }
13
+ export interface InboundHookArgs<TWire = JsonObject> {
14
+ wire: TWire;
15
+ meta: ConversionMetaBag;
16
+ context: ProtocolPipelineContext;
17
+ }
18
+ export interface CanonicalHookArgs<TCanonical> {
19
+ canonical: TCanonical;
20
+ meta: ConversionMetaBag;
21
+ context: ProtocolPipelineContext;
22
+ }
23
+ export interface OutboundWireHookArgs<TWire = JsonObject> {
24
+ wire: TWire;
25
+ meta: ConversionMetaBag;
26
+ context: ProtocolPipelineContext;
27
+ }
28
+ export interface CanonicalParseResult<TCanonical> {
29
+ canonical: TCanonical;
30
+ meta?: ConversionMetaRecord;
31
+ }
32
+ export type ProtocolParserHook<TWire, TCanonical> = (args: InboundHookArgs<TWire>) => Promise<CanonicalParseResult<TCanonical>> | CanonicalParseResult<TCanonical>;
33
+ export type ProtocolCleanupHook<TCanonical> = (args: CanonicalHookArgs<TCanonical>) => Promise<void> | void;
34
+ export interface ProtocolSerializationResult<TWire> {
35
+ payload: TWire;
36
+ meta?: ConversionMetaRecord;
37
+ }
38
+ export type ProtocolSerializerHook<TCanonical, TWire> = (args: CanonicalHookArgs<TCanonical>) => Promise<ProtocolSerializationResult<TWire>> | ProtocolSerializationResult<TWire>;
39
+ export type ProtocolAugmentationHook<TCanonical> = (args: CanonicalHookArgs<TCanonical>) => Promise<void> | void;
40
+ export interface ProtocolValidationErrorDetail {
41
+ path?: string;
42
+ message: string;
43
+ code?: string;
44
+ }
45
+ export interface ProtocolValidationResult {
46
+ ok: boolean;
47
+ errors?: ProtocolValidationErrorDetail[];
48
+ }
49
+ export type ProtocolValidationHook<TArgs> = (args: TArgs) => Promise<void | ProtocolValidationResult> | void | ProtocolValidationResult;
50
+ export type InboundValidationHook<TWire> = ProtocolValidationHook<InboundHookArgs<TWire>>;
51
+ export type OutboundValidationHook<TWire> = ProtocolValidationHook<OutboundWireHookArgs<TWire>>;
52
+ export interface ProtocolInboundHooks<TInboundWire = JsonObject, TCanonical = CanonicalChatRequest> {
53
+ preValidate?: InboundValidationHook<TInboundWire>;
54
+ parse: ProtocolParserHook<TInboundWire, TCanonical>;
55
+ cleanup?: ProtocolCleanupHook<TCanonical>;
56
+ }
57
+ export interface ProtocolOutboundHooks<TCanonical = CanonicalChatResponse, TOutboundWire = JsonObject> {
58
+ augment?: ProtocolAugmentationHook<TCanonical>;
59
+ serialize: ProtocolSerializerHook<TCanonical, TOutboundWire>;
60
+ postValidate?: OutboundValidationHook<TOutboundWire>;
61
+ }
62
+ export interface ProtocolPipelineHooks<TInboundWire = JsonObject, TOutboundWire = JsonObject, TCanonicalInbound = CanonicalChatRequest, TCanonicalOutbound = CanonicalChatResponse> {
63
+ id: string;
64
+ protocol: string;
65
+ inbound: ProtocolInboundHooks<TInboundWire, TCanonicalInbound>;
66
+ outbound: ProtocolOutboundHooks<TCanonicalOutbound, TOutboundWire>;
67
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,35 @@
1
+ import { type CanonicalChatRequest, type CanonicalChatResponse } from './schema/index.js';
2
+ import { type ProtocolPipelineHooks, type ProtocolPipelineContext, type ProtocolValidationErrorDetail } from './hooks/protocol-hooks.js';
3
+ import { ConversionMetaBag, type ConversionMetaInput } from './meta/meta-bag.js';
4
+ export interface ProtocolInboundPipelineOptions<TWire> {
5
+ payload: TWire;
6
+ context?: ProtocolPipelineContext;
7
+ meta?: ConversionMetaInput;
8
+ }
9
+ export interface ProtocolOutboundPipelineOptions<TCanonical> {
10
+ canonical: TCanonical;
11
+ context?: ProtocolPipelineContext;
12
+ meta?: ConversionMetaInput;
13
+ }
14
+ export interface ProtocolInboundPipelineResult<TCanonical> {
15
+ canonical: TCanonical;
16
+ meta: ConversionMetaBag;
17
+ context: ProtocolPipelineContext;
18
+ }
19
+ export interface ProtocolOutboundPipelineResult<TWire> {
20
+ payload: TWire;
21
+ meta: ConversionMetaBag;
22
+ context: ProtocolPipelineContext;
23
+ }
24
+ export declare class PipelineValidationError extends Error {
25
+ readonly stage: string;
26
+ readonly errors: ProtocolValidationErrorDetail[];
27
+ constructor(stage: string, errors: ProtocolValidationErrorDetail[]);
28
+ }
29
+ export declare class ProtocolConversionPipeline<TInboundWire = Record<string, unknown>, TOutboundWire = Record<string, unknown>, TCanonicalInbound = CanonicalChatRequest, TCanonicalOutbound = CanonicalChatResponse> {
30
+ private readonly hooks;
31
+ constructor(hooks: ProtocolPipelineHooks<TInboundWire, TOutboundWire, TCanonicalInbound, TCanonicalOutbound>);
32
+ convertInbound(options: ProtocolInboundPipelineOptions<TInboundWire>): Promise<ProtocolInboundPipelineResult<TCanonicalInbound>>;
33
+ convertOutbound(options: ProtocolOutboundPipelineOptions<TCanonicalOutbound>): Promise<ProtocolOutboundPipelineResult<TOutboundWire>>;
34
+ private runValidation;
35
+ }
@@ -0,0 +1,103 @@
1
+ import { ConversionMetaBag } from './meta/meta-bag.js';
2
+ export class PipelineValidationError extends Error {
3
+ stage;
4
+ errors;
5
+ constructor(stage, errors) {
6
+ super(errors[0]?.message ?? `Validation failed during ${stage}`);
7
+ this.name = 'PipelineValidationError';
8
+ this.stage = stage;
9
+ this.errors = errors;
10
+ }
11
+ }
12
+ function normalizeContext(hooks, ctx) {
13
+ return {
14
+ profileId: ctx?.profileId ?? hooks.id,
15
+ providerProtocol: ctx?.providerProtocol ?? hooks.protocol,
16
+ targetProtocol: ctx?.targetProtocol ?? ctx?.providerProtocol ?? hooks.protocol,
17
+ entryEndpoint: ctx?.entryEndpoint,
18
+ requestId: ctx?.requestId,
19
+ stream: ctx?.stream,
20
+ metadata: ctx?.metadata ?? {}
21
+ };
22
+ }
23
+ function ingestMeta(target, incoming) {
24
+ if (!incoming) {
25
+ return;
26
+ }
27
+ target.ingest(incoming);
28
+ }
29
+ export class ProtocolConversionPipeline {
30
+ hooks;
31
+ constructor(hooks) {
32
+ if (!hooks?.inbound?.parse) {
33
+ throw new Error('ProtocolConversionPipeline requires an inbound.parse hook');
34
+ }
35
+ if (!hooks?.outbound?.serialize) {
36
+ throw new Error('ProtocolConversionPipeline requires an outbound.serialize hook');
37
+ }
38
+ this.hooks = hooks;
39
+ }
40
+ async convertInbound(options) {
41
+ const context = normalizeContext(this.hooks, options.context);
42
+ const meta = new ConversionMetaBag(options.meta);
43
+ await this.runValidation('inbound.preValidate', this.hooks.inbound.preValidate, {
44
+ wire: options.payload,
45
+ meta,
46
+ context
47
+ });
48
+ const parseResult = await this.hooks.inbound.parse({
49
+ wire: options.payload,
50
+ meta,
51
+ context
52
+ });
53
+ ingestMeta(meta, parseResult.meta);
54
+ const canonical = parseResult.canonical;
55
+ if (!canonical) {
56
+ throw new Error('ProtocolConversionPipeline inbound.parse returned an empty canonical payload');
57
+ }
58
+ if (this.hooks.inbound.cleanup) {
59
+ await this.hooks.inbound.cleanup({
60
+ canonical,
61
+ meta,
62
+ context
63
+ });
64
+ }
65
+ return { canonical, meta, context };
66
+ }
67
+ async convertOutbound(options) {
68
+ const context = normalizeContext(this.hooks, options.context);
69
+ const meta = new ConversionMetaBag(options.meta);
70
+ if (this.hooks.outbound.augment) {
71
+ await this.hooks.outbound.augment({
72
+ canonical: options.canonical,
73
+ meta,
74
+ context
75
+ });
76
+ }
77
+ const serialized = await this.hooks.outbound.serialize({
78
+ canonical: options.canonical,
79
+ meta,
80
+ context
81
+ });
82
+ ingestMeta(meta, serialized.meta);
83
+ await this.runValidation('outbound.postValidate', this.hooks.outbound.postValidate, {
84
+ wire: serialized.payload,
85
+ meta,
86
+ context
87
+ });
88
+ return { payload: serialized.payload, meta, context };
89
+ }
90
+ async runValidation(stage, hook, args) {
91
+ if (!hook) {
92
+ return;
93
+ }
94
+ const result = await hook(args);
95
+ if (!result) {
96
+ return;
97
+ }
98
+ const errors = result.errors ?? [];
99
+ if (result.ok === false || errors.length > 0) {
100
+ throw new PipelineValidationError(stage, errors.length ? errors : [{ message: 'Unknown validation error' }]);
101
+ }
102
+ }
103
+ }