@jsonstudio/rcc 0.89.1205 → 0.89.1457

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 (391) hide show
  1. package/README.md +53 -1412
  2. package/configsamples/config.json +426 -0
  3. package/configsamples/config.reference.json +58 -0
  4. package/configsamples/provider/crs/config.v1.json +46 -0
  5. package/configsamples/provider/glm/config.v1.json +81 -0
  6. package/configsamples/provider/glm-anthropic/config.v1.json +45 -0
  7. package/configsamples/provider/iflow/config.v1.json +74 -0
  8. package/configsamples/provider/kimi/config.v1.json +41 -0
  9. package/configsamples/provider/lmstudio/config.v1.json +101 -0
  10. package/configsamples/provider/mimo/config.v1.json +35 -0
  11. package/configsamples/provider/modelscope/config.v1.json +96 -0
  12. package/configsamples/provider/qwen/config.v1.json +38 -0
  13. package/configsamples/provider/tab/config.v1.json +50 -0
  14. package/configsamples/provider/tabglm/config.v1.json +49 -0
  15. package/dist/build-info.js +2 -2
  16. package/dist/cli/commands/code.js +12 -6
  17. package/dist/cli/commands/code.js.map +1 -1
  18. package/dist/cli/commands/config.d.ts +2 -1
  19. package/dist/cli/commands/config.js +77 -103
  20. package/dist/cli/commands/config.js.map +1 -1
  21. package/dist/cli/commands/examples.js +6 -6
  22. package/dist/cli/commands/examples.js.map +1 -1
  23. package/dist/cli/commands/init.d.ts +28 -0
  24. package/dist/cli/commands/init.js +94 -0
  25. package/dist/cli/commands/init.js.map +1 -0
  26. package/dist/cli/commands/port.js +10 -2
  27. package/dist/cli/commands/port.js.map +1 -1
  28. package/dist/cli/commands/restart.js +5 -2
  29. package/dist/cli/commands/restart.js.map +1 -1
  30. package/dist/cli/commands/start.js +25 -22
  31. package/dist/cli/commands/start.js.map +1 -1
  32. package/dist/cli/commands/status.js +1 -0
  33. package/dist/cli/commands/status.js.map +1 -1
  34. package/dist/cli/commands/stop.js +1 -0
  35. package/dist/cli/commands/stop.js.map +1 -1
  36. package/dist/cli/config/bundled-docs.d.ts +20 -0
  37. package/dist/cli/config/bundled-docs.js +91 -0
  38. package/dist/cli/config/bundled-docs.js.map +1 -0
  39. package/dist/cli/config/init-config.d.ts +37 -0
  40. package/dist/cli/config/init-config.js +212 -0
  41. package/dist/cli/config/init-config.js.map +1 -0
  42. package/dist/cli/config/init-provider-catalog.d.ts +8 -0
  43. package/dist/cli/config/init-provider-catalog.js +187 -0
  44. package/dist/cli/config/init-provider-catalog.js.map +1 -0
  45. package/dist/cli/register/init-command.d.ts +3 -0
  46. package/dist/cli/register/init-command.js +5 -0
  47. package/dist/cli/register/init-command.js.map +1 -0
  48. package/dist/cli.js +28 -3
  49. package/dist/cli.js.map +1 -1
  50. package/dist/client/gemini/gemini-protocol-client.js +2 -1
  51. package/dist/client/gemini/gemini-protocol-client.js.map +1 -1
  52. package/dist/client/gemini-cli/gemini-cli-protocol-client.js +40 -16
  53. package/dist/client/gemini-cli/gemini-cli-protocol-client.js.map +1 -1
  54. package/dist/client/openai/chat-protocol-client.js +2 -1
  55. package/dist/client/openai/chat-protocol-client.js.map +1 -1
  56. package/dist/client/responses/responses-protocol-client.js +2 -1
  57. package/dist/client/responses/responses-protocol-client.js.map +1 -1
  58. package/dist/config/risk-control-config.d.ts +94 -0
  59. package/dist/config/risk-control-config.js +196 -0
  60. package/dist/config/risk-control-config.js.map +1 -0
  61. package/dist/constants/index.d.ts +6 -0
  62. package/dist/constants/index.js +13 -0
  63. package/dist/constants/index.js.map +1 -1
  64. package/dist/docs/daemon-admin-ui.html +2113 -190
  65. package/dist/error-handling/quiet-error-handling-center.js +46 -8
  66. package/dist/error-handling/quiet-error-handling-center.js.map +1 -1
  67. package/dist/index.js +0 -1
  68. package/dist/index.js.map +1 -1
  69. package/dist/manager/modules/health/index.d.ts +1 -1
  70. package/dist/manager/modules/quota/antigravity-quota-manager.d.ts +70 -0
  71. package/dist/manager/modules/quota/antigravity-quota-manager.js +442 -0
  72. package/dist/manager/modules/quota/antigravity-quota-manager.js.map +1 -0
  73. package/dist/manager/modules/quota/index.d.ts +3 -127
  74. package/dist/manager/modules/quota/index.js +2 -1093
  75. package/dist/manager/modules/quota/index.js.map +1 -1
  76. package/dist/manager/modules/quota/provider-key-normalization.d.ts +3 -0
  77. package/dist/manager/modules/quota/provider-key-normalization.js +155 -0
  78. package/dist/manager/modules/quota/provider-key-normalization.js.map +1 -0
  79. package/dist/manager/modules/quota/provider-quota-daemon.cooldown.d.ts +9 -0
  80. package/dist/manager/modules/quota/provider-quota-daemon.cooldown.js +115 -0
  81. package/dist/manager/modules/quota/provider-quota-daemon.cooldown.js.map +1 -0
  82. package/dist/manager/modules/quota/provider-quota-daemon.d.ts +77 -0
  83. package/dist/manager/modules/quota/provider-quota-daemon.events.d.ts +12 -0
  84. package/dist/manager/modules/quota/provider-quota-daemon.events.js +239 -0
  85. package/dist/manager/modules/quota/provider-quota-daemon.events.js.map +1 -0
  86. package/dist/manager/modules/quota/provider-quota-daemon.js +404 -0
  87. package/dist/manager/modules/quota/provider-quota-daemon.js.map +1 -0
  88. package/dist/manager/modules/quota/provider-quota-daemon.model-backoff.d.ts +11 -0
  89. package/dist/manager/modules/quota/provider-quota-daemon.model-backoff.js +192 -0
  90. package/dist/manager/modules/quota/provider-quota-daemon.model-backoff.js.map +1 -0
  91. package/dist/manager/modules/quota/provider-quota-daemon.snapshot.d.ts +8 -0
  92. package/dist/manager/modules/quota/provider-quota-daemon.snapshot.js +96 -0
  93. package/dist/manager/modules/quota/provider-quota-daemon.snapshot.js.map +1 -0
  94. package/dist/manager/modules/quota/provider-quota-daemon.view.d.ts +19 -0
  95. package/dist/manager/modules/quota/provider-quota-daemon.view.js +37 -0
  96. package/dist/manager/modules/quota/provider-quota-daemon.view.js.map +1 -0
  97. package/dist/manager/modules/routing/index.d.ts +1 -0
  98. package/dist/manager/modules/routing/index.js +11 -25
  99. package/dist/manager/modules/routing/index.js.map +1 -1
  100. package/dist/manager/quota/provider-quota-center.d.ts +2 -0
  101. package/dist/manager/quota/provider-quota-center.js +80 -82
  102. package/dist/manager/quota/provider-quota-center.js.map +1 -1
  103. package/dist/modules/llmswitch/bridge.d.ts +16 -18
  104. package/dist/modules/llmswitch/bridge.js +293 -94
  105. package/dist/modules/llmswitch/bridge.js.map +1 -1
  106. package/dist/modules/llmswitch/core-loader.d.ts +4 -2
  107. package/dist/modules/llmswitch/core-loader.js +32 -20
  108. package/dist/modules/llmswitch/core-loader.js.map +1 -1
  109. package/dist/modules/pipeline/utils/colored-logger.js +3 -2
  110. package/dist/modules/pipeline/utils/colored-logger.js.map +1 -1
  111. package/dist/modules/pipeline/utils/debug-logger.js +1 -1
  112. package/dist/modules/pipeline/utils/debug-logger.js.map +1 -1
  113. package/dist/providers/auth/antigravity-userinfo-helper.d.ts +2 -1
  114. package/dist/providers/auth/antigravity-userinfo-helper.js +25 -4
  115. package/dist/providers/auth/antigravity-userinfo-helper.js.map +1 -1
  116. package/dist/providers/auth/iflow-cookie-auth.js +0 -2
  117. package/dist/providers/auth/iflow-cookie-auth.js.map +1 -1
  118. package/dist/providers/auth/oauth-lifecycle.js +2 -23
  119. package/dist/providers/auth/oauth-lifecycle.js.map +1 -1
  120. package/dist/providers/auth/tokenfile-auth.d.ts +2 -0
  121. package/dist/providers/auth/tokenfile-auth.js +33 -1
  122. package/dist/providers/auth/tokenfile-auth.js.map +1 -1
  123. package/dist/providers/core/config/camoufox-launcher.d.ts +5 -0
  124. package/dist/providers/core/config/camoufox-launcher.js +40 -4
  125. package/dist/providers/core/config/camoufox-launcher.js.map +1 -1
  126. package/dist/providers/core/config/service-profiles.js +7 -18
  127. package/dist/providers/core/config/service-profiles.js.map +1 -1
  128. package/dist/providers/core/runtime/antigravity-quota-client.js +6 -3
  129. package/dist/providers/core/runtime/antigravity-quota-client.js.map +1 -1
  130. package/dist/providers/core/runtime/base-provider.d.ts +2 -7
  131. package/dist/providers/core/runtime/base-provider.js +84 -165
  132. package/dist/providers/core/runtime/base-provider.js.map +1 -1
  133. package/dist/providers/core/runtime/gemini-cli-http-provider.d.ts +7 -0
  134. package/dist/providers/core/runtime/gemini-cli-http-provider.js +368 -97
  135. package/dist/providers/core/runtime/gemini-cli-http-provider.js.map +1 -1
  136. package/dist/providers/core/runtime/http-request-executor.d.ts +3 -0
  137. package/dist/providers/core/runtime/http-request-executor.js +110 -38
  138. package/dist/providers/core/runtime/http-request-executor.js.map +1 -1
  139. package/dist/providers/core/runtime/http-transport-provider.d.ts +17 -0
  140. package/dist/providers/core/runtime/http-transport-provider.js +165 -16
  141. package/dist/providers/core/runtime/http-transport-provider.js.map +1 -1
  142. package/dist/providers/core/runtime/provider-error-classifier.js +10 -0
  143. package/dist/providers/core/runtime/provider-error-classifier.js.map +1 -1
  144. package/dist/providers/core/runtime/provider-factory.js +7 -5
  145. package/dist/providers/core/runtime/provider-factory.js.map +1 -1
  146. package/dist/providers/core/runtime/provider-runtime-metadata.d.ts +6 -0
  147. package/dist/providers/core/runtime/provider-runtime-metadata.js.map +1 -1
  148. package/dist/providers/core/runtime/rate-limit-manager.d.ts +1 -12
  149. package/dist/providers/core/runtime/rate-limit-manager.js +4 -77
  150. package/dist/providers/core/runtime/rate-limit-manager.js.map +1 -1
  151. package/dist/providers/core/runtime/responses-provider.d.ts +1 -7
  152. package/dist/providers/core/runtime/responses-provider.js +12 -93
  153. package/dist/providers/core/runtime/responses-provider.js.map +1 -1
  154. package/dist/providers/core/strategies/oauth-auth-code-flow.js +12 -8
  155. package/dist/providers/core/strategies/oauth-auth-code-flow.js.map +1 -1
  156. package/dist/providers/core/utils/http-client.js +36 -46
  157. package/dist/providers/core/utils/http-client.js.map +1 -1
  158. package/dist/providers/core/utils/provider-error-logger.d.ts +1 -1
  159. package/dist/providers/core/utils/provider-error-reporter.d.ts +3 -1
  160. package/dist/providers/core/utils/provider-error-reporter.js +3 -0
  161. package/dist/providers/core/utils/provider-error-reporter.js.map +1 -1
  162. package/dist/providers/core/utils/snapshot-writer.js +1 -4
  163. package/dist/providers/core/utils/snapshot-writer.js.map +1 -1
  164. package/dist/providers/mock/mock-provider-runtime.js +57 -27
  165. package/dist/providers/mock/mock-provider-runtime.js.map +1 -1
  166. package/dist/scripts/camoufox/launch-auth.mjs +193 -58
  167. package/dist/server/handlers/handler-utils.js +8 -3
  168. package/dist/server/handlers/handler-utils.js.map +1 -1
  169. package/dist/server/handlers/responses-handler.js +1 -1
  170. package/dist/server/handlers/responses-handler.js.map +1 -1
  171. package/dist/server/runtime/http-server/daemon-admin/auth-handler.d.ts +2 -0
  172. package/dist/server/runtime/http-server/daemon-admin/auth-handler.js +103 -0
  173. package/dist/server/runtime/http-server/daemon-admin/auth-handler.js.map +1 -0
  174. package/dist/server/runtime/http-server/daemon-admin/auth-session.d.ts +5 -0
  175. package/dist/server/runtime/http-server/daemon-admin/auth-session.js +77 -0
  176. package/dist/server/runtime/http-server/daemon-admin/auth-session.js.map +1 -0
  177. package/dist/server/runtime/http-server/daemon-admin/auth-store.d.ts +18 -0
  178. package/dist/server/runtime/http-server/daemon-admin/auth-store.js +89 -0
  179. package/dist/server/runtime/http-server/daemon-admin/auth-store.js.map +1 -0
  180. package/dist/server/runtime/http-server/daemon-admin/credentials-handler.js +1 -2
  181. package/dist/server/runtime/http-server/daemon-admin/credentials-handler.js.map +1 -1
  182. package/dist/server/runtime/http-server/daemon-admin/providers-handler.js +226 -24
  183. package/dist/server/runtime/http-server/daemon-admin/providers-handler.js.map +1 -1
  184. package/dist/server/runtime/http-server/daemon-admin/quota-handler.js +47 -8
  185. package/dist/server/runtime/http-server/daemon-admin/quota-handler.js.map +1 -1
  186. package/dist/server/runtime/http-server/daemon-admin/restart-handler.js +1 -1
  187. package/dist/server/runtime/http-server/daemon-admin/restart-handler.js.map +1 -1
  188. package/dist/server/runtime/http-server/daemon-admin/stats-handler.js +1 -1
  189. package/dist/server/runtime/http-server/daemon-admin/stats-handler.js.map +1 -1
  190. package/dist/server/runtime/http-server/daemon-admin/status-handler.js +68 -4
  191. package/dist/server/runtime/http-server/daemon-admin/status-handler.js.map +1 -1
  192. package/dist/server/runtime/http-server/daemon-admin-routes.d.ts +3 -4
  193. package/dist/server/runtime/http-server/daemon-admin-routes.js +9 -14
  194. package/dist/server/runtime/http-server/daemon-admin-routes.js.map +1 -1
  195. package/dist/server/runtime/http-server/executor-metadata.js +1 -1
  196. package/dist/server/runtime/http-server/executor-metadata.js.map +1 -1
  197. package/dist/server/runtime/http-server/executor-response.js +0 -16
  198. package/dist/server/runtime/http-server/executor-response.js.map +1 -1
  199. package/dist/server/runtime/http-server/hub-shadow-compare.js +110 -34
  200. package/dist/server/runtime/http-server/hub-shadow-compare.js.map +1 -1
  201. package/dist/server/runtime/http-server/index.d.ts +5 -3
  202. package/dist/server/runtime/http-server/index.js +281 -136
  203. package/dist/server/runtime/http-server/index.js.map +1 -1
  204. package/dist/server/runtime/http-server/middleware.js +19 -1
  205. package/dist/server/runtime/http-server/middleware.js.map +1 -1
  206. package/dist/server/runtime/http-server/request-executor.js +59 -24
  207. package/dist/server/runtime/http-server/request-executor.js.map +1 -1
  208. package/dist/server/runtime/http-server/routes.js +12 -3
  209. package/dist/server/runtime/http-server/routes.js.map +1 -1
  210. package/dist/server/runtime/http-server/session-dir.d.ts +2 -0
  211. package/dist/server/runtime/http-server/session-dir.js +59 -0
  212. package/dist/server/runtime/http-server/session-dir.js.map +1 -0
  213. package/dist/server/runtime/http-server/types.d.ts +0 -4
  214. package/dist/server/utils/utf8-chunk-buffer.js +6 -3
  215. package/dist/server/utils/utf8-chunk-buffer.js.map +1 -1
  216. package/dist/server/utils/warmup-storm-tracker.js +1 -1
  217. package/dist/server/utils/warmup-storm-tracker.js.map +1 -1
  218. package/dist/server-factory.d.ts +6 -28
  219. package/dist/server-factory.js +8 -93
  220. package/dist/server-factory.js.map +1 -1
  221. package/dist/token-daemon/index.js +2 -2
  222. package/dist/token-daemon/index.js.map +1 -1
  223. package/dist/token-daemon/provider-registry.js +0 -1
  224. package/dist/token-daemon/provider-registry.js.map +1 -1
  225. package/dist/token-daemon/server-utils.js +8 -9
  226. package/dist/token-daemon/server-utils.js.map +1 -1
  227. package/dist/token-daemon/token-utils.js +1 -1
  228. package/dist/token-daemon/token-utils.js.map +1 -1
  229. package/dist/tools/semantic-replay.js +2 -2
  230. package/dist/tools/semantic-replay.js.map +1 -1
  231. package/dist/tools/stats-request-events.d.ts +1 -1
  232. package/dist/tools/stats-usage.js +6 -3
  233. package/dist/tools/stats-usage.js.map +1 -1
  234. package/dist/utils/llms-engine-shadow.d.ts +19 -0
  235. package/dist/utils/llms-engine-shadow.js +209 -0
  236. package/dist/utils/llms-engine-shadow.js.map +1 -0
  237. package/dist/utils/runtime-versions.js +2 -1
  238. package/dist/utils/runtime-versions.js.map +1 -1
  239. package/dist/utils/strip-internal-keys.d.ts +12 -0
  240. package/dist/utils/strip-internal-keys.js +28 -0
  241. package/dist/utils/strip-internal-keys.js.map +1 -0
  242. package/docs/ARCHITECTURE.md +402 -0
  243. package/docs/CHAT_PROCESS_PROTOCOL_AND_PIPELINE.md +221 -0
  244. package/docs/CODEX_AND_CLAUDE_CODE.md +69 -0
  245. package/docs/CONFIG_ARCHITECTURE.md +517 -0
  246. package/docs/ERROR_HANDLING_AUDIT.md +0 -0
  247. package/docs/GCLI2API_PARITY_GAPS.md +98 -0
  248. package/docs/INSTALLATION_AND_QUICKSTART.md +74 -0
  249. package/docs/INSTRUCTION_MARKUP.md +89 -0
  250. package/docs/MODULE_ENHANCEMENT_SYSTEM.md +666 -0
  251. package/docs/PORTS.md +36 -0
  252. package/docs/PROVIDERS_BUILTIN.md +111 -0
  253. package/docs/PROVIDER_TYPES.md +55 -0
  254. package/docs/SERVERTOOL_CLOCK_DESIGN.md +233 -0
  255. package/docs/USAGE_HANDLING_ANALYSIS.md +335 -0
  256. package/docs/USER_CONFIG_PARSER_CHANGES.md +175 -0
  257. package/docs/V3_INBOUND_OUTBOUND_DESIGN.md +86 -0
  258. package/docs/VIRTUAL_ROUTER_PRIORITY_AND_HEALTH.md +125 -0
  259. package/docs/anthropic-request-golden-samples.md +50 -0
  260. package/docs/antigravity-gemini-format-cleanup.md +102 -0
  261. package/docs/antigravity-routing-contract.md +31 -0
  262. package/docs/ccr-alignment-enhancetool.md +105 -0
  263. package/docs/chat-glm-500-analysis.md +79 -0
  264. package/docs/chat-request-golden-samples.md +42 -0
  265. package/docs/chat-semantic-expansion-plan.md +84 -0
  266. package/docs/cli-command-inventory.md +76 -0
  267. package/docs/codex-samples-replay.md +50 -0
  268. package/docs/daemon-admin-api-design.md +350 -0
  269. package/docs/daemon-admin-module-structure.md +169 -0
  270. package/docs/daemon-admin-ui.html +3394 -0
  271. package/docs/debug-system-design.md +734 -0
  272. package/docs/debugging/gemini-sse-root-cause.md +52 -0
  273. package/docs/debugging/sse_encoding_failure_analysis.md +53 -0
  274. package/docs/dry-run/README.md +721 -0
  275. package/docs/error-handling-v2.md +92 -0
  276. package/docs/exec-command-guard-policy.example.v1.json +42 -0
  277. package/docs/fixes/gemini-protocol-mapping.md +57 -0
  278. package/docs/fixes/oauth-portal-timing-fix.md +202 -0
  279. package/docs/fixes/web-search-hop3-fix.md +265 -0
  280. package/docs/glm-api-reference.md +390 -0
  281. package/docs/glm-chat-completions.md +1779 -0
  282. package/docs/glm-history-inline-images.md +44 -0
  283. package/docs/golden-ci-library.md +66 -0
  284. package/docs/lmstudio-dry-run-summary.md +203 -0
  285. package/docs/lmstudio-tool-calling.md +214 -0
  286. package/docs/mapping-tables/anthropic-to-openai.json +290 -0
  287. package/docs/mapping-tables/iflow-to-openai.json +215 -0
  288. package/docs/mapping-tables/openai-passthrough.json +190 -0
  289. package/docs/mapping-tables/openai-to-iflow.json +227 -0
  290. package/docs/monitoring/Design.md +61 -0
  291. package/docs/multi-token-auth-guide.md +66 -0
  292. package/docs/oauth-authentication-guide.md +168 -0
  293. package/docs/oauth-iflow-implementation.md +153 -0
  294. package/docs/pipeline-routing-report.md +209 -0
  295. package/docs/plans/manager-daemon/PLAN.md +86 -0
  296. package/docs/plans/provider-config-v2-plan.md +176 -0
  297. package/docs/plans/provider-runtime-manager-plan.md +209 -0
  298. package/docs/plans/transparent-429-failover.md +89 -0
  299. package/docs/plans/unified-hub-framework-v1.md +245 -0
  300. package/docs/provider-config-v2-ui-design.md +181 -0
  301. package/docs/provider-quota-design.md +129 -0
  302. package/docs/providers/gemini-provider.md +62 -0
  303. package/docs/providers/lmstudio-v2-migration-report.md +102 -0
  304. package/docs/providers/provider-composite-design.md +142 -0
  305. package/docs/providers/provider-composite-testing.md +98 -0
  306. package/docs/providers/provider-type-only-migration.md +111 -0
  307. package/docs/rccx-wasm-migration.md +74 -0
  308. package/docs/refactoring/architecture-comparison-diagram.md +140 -0
  309. package/docs/refactoring/compatibility-v2-architecture-design.md +738 -0
  310. package/docs/refactoring/workflow-compatibility-refactoring-design.md +361 -0
  311. package/docs/reports/routing-classification-report.json +24 -0
  312. package/docs/reports/routing-classification-report.md +18 -0
  313. package/docs/reports/thinking-keywords-report.json +19 -0
  314. package/docs/responses/README.md +156 -0
  315. package/docs/responses-generic-provider.md +86 -0
  316. package/docs/responses-passthrough-provider-design.md +202 -0
  317. package/docs/routing-awrr-health-weighted-round-robin.md +179 -0
  318. package/docs/routing-instructions.md +393 -0
  319. package/docs/servertool-framework.md +65 -0
  320. package/docs/stop-message-auto.md +225 -0
  321. package/docs/streaming-flow.html +30 -0
  322. package/docs/streaming-flow.md +182 -0
  323. package/docs/token-daemon-preview.html +490 -0
  324. package/docs/token-refresh-daemon-plan.md +269 -0
  325. package/docs/transformation-tables/Gemini-FinishReason/345/256/214/346/225/264/350/275/254/346/215/242/350/241/250.json +233 -0
  326. package/docs/transformation-tables/README.md +225 -0
  327. package/docs/transformation-tables/claude-code-router-anthropic-to-gemini.json +283 -0
  328. package/docs/transformation-tables/claude-code-router-anthropic-to-openai.json +208 -0
  329. package/docs/transformation-tables/claude-code-router-openai-to-anthropic.json +261 -0
  330. package/docs/transformation-tables/claude-code-router-openai-to-gemini.json +208 -0
  331. package/docs/transformation-tables/claude-code-router-openai-to-lmstudio.json +182 -0
  332. package/docs/transformation-tables/claude-code-router-openai-to-ollama.json +250 -0
  333. package/docs/transformation-tables/claude-code-router-openai-to-textgenwebui.json +295 -0
  334. package/docs/transformation-tables/claude-code-router-provider-conversions.json +193 -0
  335. package/docs/transformation-tables//345/256/214/346/225/264/347/232/204/345/267/245/345/205/267/346/211/247/350/241/214/346/265/201/347/250/213/350/275/254/346/215/242/350/241/250.json +299 -0
  336. package/docs/transformation-tables//345/257/271/350/257/235/345/216/206/345/217/262/347/273/264/346/212/244/345/210/206/346/236/220.md +134 -0
  337. package/docs/transformation-tables//345/267/245/345/205/267/350/260/203/347/224/250/346/250/241/345/274/217/345/210/206/346/236/220.md +158 -0
  338. package/docs/transformation-tables//347/212/266/346/200/201/347/256/241/347/220/206/351/234/200/346/261/202/345/210/206/346/236/220.md +175 -0
  339. package/docs/transformation-tables//351/235/231/346/200/201/350/241/250vs/345/212/250/346/200/201/345/210/206/346/236/220.md +189 -0
  340. package/docs/transformation-tables//351/235/231/346/200/201/350/241/250/345/207/206/347/241/256/346/200/247/350/257/204/344/274/260.md +179 -0
  341. package/docs/transformation-tables//351/235/236/346/265/201/345/274/217/345/234/272/346/231/257/345/210/206/346/236/220.md +189 -0
  342. package/docs/v2-architecture/IMPLEMENTATION-ROADMAP.md +367 -0
  343. package/docs/v2-architecture/OPTIMIZED-DESIGN.md +827 -0
  344. package/docs/v2-architecture/PRERUN-CONNECTION-DESIGN.md +716 -0
  345. package/docs/v2-architecture/README.md +549 -0
  346. package/docs/verification/modelscope-verify.md +59 -0
  347. package/docs/verified-configs/README.md +60 -0
  348. package/docs/verified-configs/v0.45.0/README.md +244 -0
  349. package/docs/verified-configs/v0.45.0/lmstudio-5521-gpt-oss-20b-mlx.json +135 -0
  350. package/docs/verified-configs/v0.45.0/merged-config.5521.json +1205 -0
  351. package/docs/verified-configs/v0.45.0/merged-config.qwen-5522.json +1559 -0
  352. package/docs/verified-configs/v0.45.0/qwen-5522-qwen3-coder-plus-final.json +221 -0
  353. package/docs/verified-configs/v0.45.0/qwen-5522-qwen3-coder-plus-fixed.json +242 -0
  354. package/docs/verified-configs/v0.45.0/qwen-5522-qwen3-coder-plus.json +242 -0
  355. package/docs/web-search-service-design.md +322 -0
  356. package/package.json +26 -15
  357. package/scripts/build-core.mjs +3 -1
  358. package/scripts/camoufox/launch-auth.mjs +193 -58
  359. package/scripts/ci/repo-sanity.mjs +138 -0
  360. package/scripts/mock-provider/run-regressions.mjs +157 -1
  361. package/scripts/monitor-diff.mjs +126 -0
  362. package/scripts/pack-mode.mjs +19 -1
  363. package/scripts/pack-rcc.mjs +63 -0
  364. package/scripts/run-bg.sh +0 -14
  365. package/scripts/tests/ci-jest.mjs +119 -0
  366. package/scripts/tools-dev/responses-debug-client/README.md +23 -0
  367. package/scripts/tools-dev/responses-debug-client/payloads/poem.json +13 -0
  368. package/scripts/tools-dev/responses-debug-client/payloads/sample-no-tools.json +98 -0
  369. package/scripts/tools-dev/responses-debug-client/payloads/text.json +13 -0
  370. package/scripts/tools-dev/responses-debug-client/payloads/tool.json +27 -0
  371. package/scripts/tools-dev/responses-debug-client/run.mjs +65 -0
  372. package/scripts/tools-dev/responses-debug-client/src/index.ts +281 -0
  373. package/scripts/tools-dev/run-llmswitch-chat.mjs +53 -0
  374. package/scripts/tools-dev/server-tools-dev/run-web-fetch.mjs +65 -0
  375. package/scripts/unified-hub-shadow-compare.mjs +33 -13
  376. package/scripts/vendor-core.mjs +13 -3
  377. package/scripts/verify-e2e-toolcall.mjs +115 -26
  378. package/dist/modules/llmswitch/pipeline-registry.d.ts +0 -57
  379. package/dist/modules/llmswitch/pipeline-registry.js +0 -229
  380. package/dist/modules/llmswitch/pipeline-registry.js.map +0 -1
  381. package/dist/server/RouteCodexServer.d.ts +0 -13
  382. package/dist/server/RouteCodexServer.js +0 -25
  383. package/dist/server/RouteCodexServer.js.map +0 -1
  384. package/dist/v2/conversion/hub/snapshot-recorder.d.ts +0 -12
  385. package/dist/v2/conversion/hub/snapshot-recorder.js +0 -22
  386. package/dist/v2/conversion/hub/snapshot-recorder.js.map +0 -1
  387. package/scripts/test-fc-responses.mjs +0 -66
  388. package/scripts/test-guidance.mjs +0 -100
  389. package/scripts/test-iflow-web-search.mjs +0 -141
  390. package/scripts/test-iflow.mjs +0 -379
  391. package/scripts/test-tool-exec.mjs +0 -26
@@ -0,0 +1,549 @@
1
+ # V2 Pipeline Architecture Design
2
+
3
+ > **Status**: This blueprint is frozen. Current implementation follows AGENTS.md principles (single execution path, no bypasses). This doc is retained for historical reference only; do not use as current architecture guidance.
4
+
5
+ ## 🎯 Design Objectives
6
+
7
+ This document outlines the V2 pipeline architecture design for RouteCodex, focusing on:
8
+
9
+ 1. **Gradual Migration**: V2 refactoring with seamless V1/V2 switching
10
+ 2. **Virtual Pipeline**: Dynamic routing replacing static assembly
11
+ 3. **Unified Configuration**: Complete V2 configuration system
12
+ 4. **System Integration Hooks**: Global hooks for request lifecycle management
13
+
14
+ ## 🏗️ Overall Architecture
15
+
16
+ ### Architecture Comparison
17
+
18
+ ```
19
+ ┌─────────────────────────────────────────────────────────────────┐
20
+ │ V1/V2 Dual Mode Architecture │
21
+ ├─────────────────────────────────────────────────────────────────┤
22
+ │ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │
23
+ │ │ Mode Switch │ │ Route Selector│ │ Config Manager │ │
24
+ │ │ (Feature Flag) │ │ (Route Selector)│ │ (Config Manager) │ │
25
+ │ └─────────────────┘ └─────────────────┘ └─────────────────┘ │
26
+ │ │ │ │ │
27
+ │ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │
28
+ │ │ V1 Static │ │ V2 Virtual │ │ System Hooks │ │
29
+ │ │ (Static Build) │ │ (Dynamic Route) │ │ (System Hooks) │ │
30
+ │ └─────────────────┘ └─────────────────┘ └─────────────────┘ │
31
+ └─────────────────────────────────────────────────────────────────┘
32
+ ```
33
+
34
+ ## 📋 Phase 1: V2 Virtual Pipeline Architecture
35
+
36
+ ### 1.1 Core Design Concept
37
+
38
+ **V1 Static Assembly** (Current):
39
+ ```
40
+ Request → Pre-assembled Pipeline → Static Module Chain → Response
41
+ [Provider][Compatibility][LLMSwitch] (Pre-instantiated)
42
+ ```
43
+
44
+ **V2 Virtual Pipeline** (New Design):
45
+ ```
46
+ Request → Route Decision → Dynamic Module Connection → Response
47
+
48
+ [Module Registry] → [Runtime Assembly] → [Temporary Connection] → [Request Process] → [Auto Cleanup]
49
+ ```
50
+
51
+ ### 1.2 V2 Core Components
52
+
53
+ #### A. Module Registry (ModuleRegistry)
54
+ ```typescript
55
+ // src/modules/pipeline/v2/core/module-registry.ts
56
+ export class V2ModuleRegistry {
57
+ private modules = new Map<string, ModuleFactory>();
58
+ private instances = new Map<string, ModuleInstance>();
59
+
60
+ // Register module factory (not instance)
61
+ register(type: string, factory: ModuleFactory): void
62
+
63
+ // Create module instance on demand (lazy loading)
64
+ createInstance(type: string, config: ModuleConfig): Promise<ModuleInstance>
65
+
66
+ // Get or create instance (singleton pattern)
67
+ getOrCreateInstance(type: string, config: ModuleConfig): Promise<ModuleInstance>
68
+
69
+ // Cleanup idle instances (memory management)
70
+ cleanupIdleInstances(): void
71
+ }
72
+ ```
73
+
74
+ #### B. Dynamic Router (DynamicRouter)
75
+ ```typescript
76
+ // src/modules/pipeline/v2/core/dynamic-router.ts
77
+ export class DynamicRouter {
78
+ constructor(
79
+ private moduleRegistry: V2ModuleRegistry,
80
+ private routeTable: RouteTable
81
+ ) {}
82
+
83
+ // Route request dynamically to module chain
84
+ async route(request: PipelineRequest): Promise<ModuleChain>
85
+
86
+ // Build temporary module connection
87
+ private async buildModuleChain(route: Route): Promise<ModuleChain>
88
+
89
+ // Execute module chain processing
90
+ async executeChain(chain: ModuleChain, request: PipelineRequest): Promise<PipelineResponse>
91
+ }
92
+ ```
93
+
94
+ #### C. Module Chain Manager (ChainManager)
95
+ ```typescript
96
+ // src/modules/pipeline/v2/core/chain-manager.ts
97
+ export class ModuleChain {
98
+ readonly id: string;
99
+ readonly modules: ModuleInstance[];
100
+ readonly connections: ModuleConnection[];
101
+
102
+ // Execute chain processing
103
+ async process(request: PipelineRequest): Promise<PipelineResponse>
104
+
105
+ // Auto cleanup connections
106
+ async cleanup(): Promise<void>
107
+ }
108
+
109
+ export class ModuleConnection {
110
+ constructor(
111
+ public from: ModuleInstance,
112
+ public to: ModuleInstance,
113
+ public transform?: (data: any) => any
114
+ ) {}
115
+ }
116
+ ```
117
+
118
+ ### 1.3 Virtual Pipeline Lifecycle
119
+
120
+ ```
121
+ 1. Request Enter → 2. Route Analysis → 3. Module Lookup → 4. Instance Check → 5. Dynamic Connection
122
+ ↓ ↓ ↓ ↓ ↓
123
+ [Request Parse] → [Route Table Match] → [Module Registry] → [Instance Cache] → [Temporary Chain Build]
124
+ ↓ ↓ ↓ ↓ ↓
125
+ 6. Chain Execute → 7. Response Return → 8. Connection Cleanup → 9. Instance Recycling → 10. Log Recording
126
+ [Data Processing] → [Result Return] → [Auto Disconnect] → [Cache Retention] → [Audit Trail]
127
+ ```
128
+
129
+ ## 📋 Phase 2: V2 Unified Configuration System
130
+
131
+ ### 2.1 V2 Configuration Schema Design
132
+
133
+ ```typescript
134
+ // src/config/v2-config-schema.ts
135
+ export interface V2SystemConfig {
136
+ version: '2.0';
137
+
138
+ // System switch configuration
139
+ system: {
140
+ mode: 'v1' | 'v2' | 'hybrid';
141
+ featureFlags: Record<string, boolean>;
142
+ };
143
+
144
+ // Global hooks configuration
145
+ hooks: SystemHooksConfig;
146
+
147
+ // V2 virtual pipeline configuration
148
+ virtualPipelines: {
149
+ routeTable: RouteTableConfig;
150
+ moduleRegistry: ModuleRegistryConfig;
151
+ chainManagement: ChainManagementConfig;
152
+ };
153
+
154
+ // V1 configuration compatibility (auto convert)
155
+ legacy?: V1Config;
156
+ }
157
+
158
+ export interface RouteTableConfig {
159
+ routes: RouteDefinition[];
160
+ defaultRoute: string;
161
+ // Note: No fallback strategies - fail fast when routing fails
162
+ }
163
+
164
+ export interface RouteDefinition {
165
+ id: string;
166
+ pattern: RequestPattern;
167
+ modules: string[]; // Module type array, not instances
168
+ config: RouteConfig;
169
+ priority: number;
170
+ }
171
+ ```
172
+
173
+ ### 2.2 Configuration Migration Adapter
174
+
175
+ ```typescript
176
+ // src/config/v2-migration-adapter.ts
177
+ export class V2MigrationAdapter {
178
+ // Auto convert V1 configuration to V2 format
179
+ static migrateV1Config(v1Config: V1Config): V2SystemConfig {
180
+ return {
181
+ version: '2.0',
182
+ system: { mode: 'v2', featureFlags: {} },
183
+ hooks: this.extractHooksFromV1(v1Config),
184
+ virtualPipelines: this.convertPipelinesToVirtual(v1Config),
185
+ legacy: v1Config // Keep original config for rollback
186
+ };
187
+ }
188
+
189
+ // Generate migration report
190
+ static generateMigrationReport(v1Config: V1Config): MigrationReport {
191
+ return {
192
+ breakingChanges: [],
193
+ newFeatures: [],
194
+ manualSteps: [],
195
+ estimatedEffort: 'low'
196
+ };
197
+ }
198
+ }
199
+ ```
200
+
201
+ ## 📋 Phase 3: V1/V2 Dual Mode Switch System
202
+
203
+ ### 3.1 Switch Design
204
+
205
+ ```typescript
206
+ // src/core/system-mode-switch.ts
207
+ export class SystemModeSwitch {
208
+ private currentMode: 'v1' | 'v2' = 'v1';
209
+ private v1Assembler?: V1PipelineAssembler;
210
+ private v2Router?: V2DynamicRouter;
211
+
212
+ // Runtime mode switching
213
+ async switchMode(mode: 'v1' | 'v2'): Promise<void> {
214
+ if (mode === this.currentMode) return;
215
+
216
+ // 1. Stop current mode
217
+ await this.stopCurrentMode();
218
+
219
+ // 2. Start target mode
220
+ await this.startTargetMode(mode);
221
+
222
+ // 3. Validate switch success
223
+ await this.validateModeSwitch(mode);
224
+
225
+ this.currentMode = mode;
226
+ }
227
+
228
+ // Handle request (auto route to current mode)
229
+ async handleRequest(request: PipelineRequest): Promise<PipelineResponse> {
230
+ return this.currentMode === 'v1'
231
+ ? this.v1Assembler!.process(request)
232
+ : this.v2Router!.route(request);
233
+ }
234
+ }
235
+ ```
236
+
237
+ ### 3.2 Hybrid Mode Design
238
+
239
+ ```typescript
240
+ // src/core/hybrid-mode-manager.ts
241
+ export class HybridModeManager {
242
+ // Select V1 or V2 based on request characteristics
243
+ selectMode(request: PipelineRequest): 'v1' | 'v2' {
244
+ // Decision based on request features, config flags, runtime state
245
+ if (this.shouldUseV2(request)) return 'v2';
246
+ return 'v1';
247
+ }
248
+
249
+ // Gradual traffic switching
250
+ async gradualTransition(percentage: number): Promise<void> {
251
+ // Gradually increase V2 traffic ratio
252
+ // Monitor key metrics
253
+ // Auto rollback mechanism
254
+ }
255
+ }
256
+ ```
257
+
258
+ ## 📋 Phase 4: System Integration Hooks
259
+
260
+ ### 4.1 Hooks Architecture Design
261
+
262
+ ```typescript
263
+ // src/hooks/system-hooks.ts
264
+ export interface SystemHooks {
265
+ // Request lifecycle hooks
266
+ onRequest?: (request: PipelineRequest) => PipelineRequest | Promise<PipelineRequest>;
267
+ beforeRoute?: (request: PipelineRequest) => void | Promise<void>;
268
+ afterRoute?: (route: Route) => void | Promise<void>;
269
+ beforeModule?: (module: ModuleInstance, data: any) => any | Promise<any>;
270
+ afterModule?: (module: ModuleInstance, result: any) => any | Promise<any>;
271
+ onResponse?: (response: PipelineResponse) => PipelineResponse | Promise<PipelineResponse>;
272
+
273
+ // System lifecycle hooks
274
+ onModeSwitch?: (from: string, to: string) => void | Promise<void>;
275
+ onError?: (error: Error, context: any) => void | Promise<void>;
276
+ onMetric?: (metric: SystemMetric) => void | Promise<void>;
277
+ }
278
+
279
+ export class SystemHookManager {
280
+ private hooks = new Map<string, SystemHook[]>();
281
+
282
+ // Register hook
283
+ register(event: string, hook: SystemHook): void
284
+
285
+ // Execute hook chain
286
+ async execute(event: string, data: any): Promise<any>
287
+
288
+ // Dynamic enable/disable hook
289
+ toggle(event: string, enabled: boolean): void
290
+ }
291
+ ```
292
+
293
+ ### 4.2 Built-in System Hooks
294
+
295
+ ```typescript
296
+ // src/hooks/builtin-hooks.ts
297
+ export class BuiltinHooks {
298
+ // Request tracking hook
299
+ static requestTracer: SystemHook = {
300
+ onRequest: async (request) => {
301
+ request.traceId = generateTraceId();
302
+ request.startTime = Date.now();
303
+ return request;
304
+ },
305
+ onResponse: async (response) => {
306
+ const duration = Date.now() - response.request.startTime;
307
+ metrics.record('request.duration', duration);
308
+ return response;
309
+ }
310
+ };
311
+
312
+ // Mode switch hook
313
+ static modeSwitchLogger: SystemHook = {
314
+ onModeSwitch: async (from, to) => {
315
+ logger.info(`System mode switched from ${from} to ${to}`, {
316
+ timestamp: new Date().toISOString(),
317
+ trigger: 'manual'
318
+ });
319
+ }
320
+ };
321
+
322
+ // Error logging hook (NO auto fallback - fail fast)
323
+ static errorLogger: SystemHook = {
324
+ onError: async (error, context) => {
325
+ // Log detailed error information for manual intervention
326
+ logger.error('V2 error detected', {
327
+ error: error.message,
328
+ stack: error.stack,
329
+ context: {
330
+ mode: context.mode,
331
+ requestId: context.requestId,
332
+ routeId: context.routeId,
333
+ timestamp: new Date().toISOString()
334
+ }
335
+ });
336
+
337
+ // Emit metrics for monitoring
338
+ metrics.increment('v2.errors.total', {
339
+ errorType: error.constructor.name,
340
+ mode: context.mode
341
+ });
342
+ }
343
+ };
344
+ }
345
+ ```
346
+
347
+ ## 📋 Phase 5: Monitoring and Observability
348
+
349
+ ### 5.1 V2 Specific Monitoring Metrics
350
+
351
+ ```typescript
352
+ // src/monitoring/v2-metrics.ts
353
+ export class V2Metrics {
354
+ // Dynamic routing metrics
355
+ routeCacheHitRate: Gauge;
356
+ moduleChainBuildTime: Histogram;
357
+ activeConnections: Gauge;
358
+
359
+ // Module instance metrics
360
+ moduleInstanceCount: Gauge;
361
+ moduleInstanceMemoryUsage: Gauge;
362
+ moduleIdleTime: Histogram;
363
+
364
+ // Mode switching metrics
365
+ modeSwitchCount: Counter;
366
+ modeSwitchLatency: Histogram;
367
+ v1VsV2RequestRatio: Gauge;
368
+ }
369
+ ```
370
+
371
+ ### 5.2 Debug Tools
372
+
373
+ ```typescript
374
+ // src/debugging/v2-debug-tools.ts
375
+ export class V2DebugTools {
376
+ // Visualize dynamic routing
377
+ async visualizeRoute(request: PipelineRequest): Promise<RouteVisualization>
378
+
379
+ // Module chain tracing
380
+ async traceModuleChain(chainId: string): Promise<ChainTrace>
381
+
382
+ // Performance analysis
383
+ async analyzePerformance(timeRange: TimeRange): Promise<PerformanceReport>
384
+
385
+ // Configuration validation
386
+ async validateV2Config(config: V2SystemConfig): Promise<ValidationReport>
387
+ }
388
+ ```
389
+
390
+ ## 🔧 Compatibility Layer Responsibilities
391
+
392
+ ### Field Mapping + Format Conversion + Provider-Specific Processing
393
+
394
+ **Compatibility层核心职责**:将特定Provider的响应格式转换为标准OpenAI格式,支持配置驱动的字段映射、格式转换和清理。
395
+
396
+ #### 核心功能组件
397
+
398
+ 1. **字段映射 (Field Mappings)**
399
+ - 将Provider特有字段映射到OpenAI标准字段
400
+ - 清理Provider特有的多余字段
401
+ - 保持字段语义的一致性
402
+
403
+ 2. **格式转换 (Format Conversions)**
404
+ - 标准化日期时间格式
405
+ - 转换使用统计格式
406
+ - 处理特殊字段的格式要求
407
+
408
+ 3. **供应商特定处理 (Provider-Specific Processing)**
409
+ - Provider特有的清理逻辑
410
+ - Provider特有的格式转换
411
+ - 基于配置的条件处理
412
+
413
+ 4. **Hooks机制**
414
+ - **beforeFieldMapping**: 字段映射前的预处理
415
+ - **afterFieldMapping**: 字段映射后的后处理
416
+ - 只处理字段映射相关的逻辑,不涉及工具处理
417
+
418
+ #### 配置驱动示例
419
+
420
+ ```typescript
421
+ 'glm-compatibility-config': {
422
+ fieldMappings: {
423
+ request: { 'model': 'model', 'messages': 'messages' },
424
+ response: {
425
+ 'choices': 'choices',
426
+ 'usage': 'usage',
427
+ 'thought': null // 清理GLM特有字段
428
+ }
429
+ },
430
+ formatConversions: {
431
+ reasoningContent: {
432
+ source: 'thought',
433
+ target: 'reasoning_content',
434
+ transform: 'extract_and_format'
435
+ }
436
+ },
437
+ hooks: {
438
+ beforeFieldMapping: ['glm-request-preprocessor'],
439
+ afterFieldMapping: ['glm-response-postprocessor']
440
+ }
441
+ }
442
+ ```
443
+
444
+ ## 🔧 Tools Unique Entrance (Principle 1-3)
445
+
446
+ ### Mandatory Tool Processing Contract
447
+
448
+ **V2 enforces llmswitch-core as the ONLY module that can touch tool calls**. This is non-negotiable and enforced at schema validation time.
449
+
450
+ #### Required Module Order
451
+ ```
452
+ provider → compatibility → llmswitch (final) → response
453
+ ```
454
+
455
+ #### llmswitch-core Exclusive Responsibilities
456
+ Only `llmswitch-core` modules may perform:
457
+
458
+ 1. **Tool Calls Canonicalization**: Normalize tool_calls structure
459
+ - Implementation: `sharedmodule/llmswitch-core/src/conversion/shared/tool-canonicalizer.ts`
460
+ 2. **Argument Stringification**: Convert tool arguments to proper string format
461
+ - Implementation: `sharedmodule/llmswitch-core/src/conversion/shared/tool-canonicalizer.ts`
462
+ 3. **Result Envelope Stripping**: Remove tool result wrapper envelopes
463
+ - Implementation: `sharedmodule/llmswitch-core/src/conversion/responses/responses-openai-bridge.ts`
464
+ 4. **Schema Augmentation**: Normalize/augment tool schemas (and inject tool guidance when enabled)
465
+ - Implementation: `sharedmodule/llmswitch-core/src/conversion/shared/tool-governor.ts` + `sharedmodule/llmswitch-core/src/guidance/index.ts`
466
+ 5. **finish_reason=tool_calls Patching**: Set correct finish reason for tool calls
467
+ - Implementation: `sharedmodule/llmswitch-core/src/conversion/responses/responses-openai-bridge.ts`
468
+
469
+ #### V2 Guardrails
470
+ - Any chain where non-llmswitch module references tool handling is rejected
471
+ - Compatibility modules can only perform field mappings and format conversions (no tool logic)
472
+ - Server/hook layers cannot modify tool calls directly
473
+ - Tool validation must use llmswitch-core validators only
474
+ - Compatibility层的hooks只处理字段映射相关的供应商特定逻辑,不涉及工具处理
475
+
476
+ #### Schema-Level Validation Enforcement
477
+ ```typescript
478
+ // Schema validation at assembly time
479
+ export class V2SchemaValidator {
480
+ static validateModuleOrder(route: RouteDefinition): ValidationResult {
481
+ // Required order: provider → compatibility → llmswitch (must be last)
482
+ const moduleTypes = route.modules.map(m => m.type);
483
+
484
+ if (moduleTypes[moduleTypes.length - 1] !== 'llmswitch') {
485
+ throw new ConfigValidationError(
486
+ `Route ${route.id} violates ToolsUniqueEntrance: llmswitch must be last module`,
487
+ ['routes', route.id, 'modules', 'order']
488
+ );
489
+ }
490
+
491
+ return { isValid: true, errors: [] };
492
+ }
493
+ }
494
+ ```
495
+
496
+ All configurations must pass schema validation at assembly time, with violations resulting in `ConfigValidationError` that exposes the exact config path for debugging.
497
+
498
+ ## 🚀 Implementation Roadmap
499
+
500
+ ### Phase 1: V2 Basic Architecture (3-4 days)
501
+ - [ ] Implement V2ModuleRegistry
502
+ - [ ] Implement DynamicRouter and ModuleChain
503
+ - [ ] Create V2 configuration schema
504
+ - [ ] Implement V2MigrationAdapter
505
+
506
+ ### Phase 2: Switch Mechanism (2-3 days)
507
+ - [ ] Implement SystemModeSwitch
508
+ - [ ] Implement HybridModeManager
509
+ - [ ] Add mode switching API
510
+ - [ ] Implement auto rollback mechanism
511
+
512
+ ### Phase 3: System Hooks (2 days)
513
+ - [ ] Implement SystemHookManager
514
+ - [ ] Create BuiltinHooks collection
515
+ - [ ] Integrate into request lifecycle
516
+ - [ ] Add hook configuration management
517
+
518
+ ### Phase 4: Monitoring & Debugging (1-2 days)
519
+ - [ ] Implement V2Metrics
520
+ - [ ] Create V2DebugTools
521
+ - [ ] Integrate into existing monitoring system
522
+ - [ ] Add debugging API endpoints
523
+
524
+ ### Phase 5: Testing & Validation (2-3 days)
525
+ - [ ] Unit test coverage
526
+ - [ ] Integration test validation
527
+ - [ ] Performance benchmark testing
528
+ - [ ] Stress test validation
529
+
530
+ ## 🎯 Key Advantages
531
+
532
+ 1. **Zero Risk Migration**: Switch back to V1 anytime, ensure business continuity
533
+ 2. **Resource Optimization**: Virtual pipeline avoids large number of pre-built instances
534
+ 3. **Flexible Routing**: Support dynamic routing decisions based on request characteristics
535
+ 4. **System Observability**: Global hooks provide complete request lifecycle intervention capability
536
+ 5. **Configuration Unification**: V2 configuration backward compatible, smooth migration
537
+
538
+ ## 📊 Risk Assessment
539
+
540
+ | Risk Item | Level | Mitigation Measures |
541
+ |-----------|-------|---------------------|
542
+ | Performance Regression | Medium | Instance caching + warmup mechanism + performance monitoring |
543
+ | Switch Failure | Low | Auto rollback + health check + state validation |
544
+ | Configuration Compatibility | Medium | Auto migration + configuration validation + manual adjustment tools |
545
+ | Memory Leaks | Medium | Auto cleanup + instance pool management + memory monitoring |
546
+
547
+ ---
548
+
549
+ *This design document serves as the blueprint for V2 architecture implementation. All components should follow these design principles and interfaces.*
@@ -0,0 +1,59 @@
1
+ # ModelScope 独立验证记录
2
+
3
+ - 日期: 2025-09-26
4
+ - 配置文件: `~/.routecodex/config/modelscope.json`
5
+ - 监听端口: 5507(示例环境)
6
+
7
+ ## 验证范围
8
+
9
+ - 非流式 Chat Completions:返回 OpenAI 标准结构(`id/object/created/model/choices/usage`)
10
+ - 流式 Chat Completions(SSE):`object: chat.completion.chunk`,`delta.content` 正常输出,`[DONE]` 终止
11
+ - 严格 JSON 模式:`response_format: { "type": "json_object" }` 时,`message.content` 清洗为纯 JSON 字符串
12
+ - 429 调度:由 PipelineManager 统一处理,多 Key/Pipeline 轮询重试;全部枯竭才返回 429
13
+ - 统一响应头:`x-request-id`、`Cache-Control: no-store`、`Content-Type: application/json; charset=utf-8`
14
+
15
+ ## 快速验证命令
16
+
17
+ 非流式:
18
+
19
+ ```
20
+ curl -i -sS -H 'Content-Type: application/json' \
21
+ -X POST http://localhost:5507/v1/chat/completions \
22
+ -d '{
23
+ "model": "Qwen/Qwen3-Coder-480B-A35B-Instruct",
24
+ "messages": [{"role":"user","content":"Hello from ModelScope test."}],
25
+ "stream": false
26
+ }'
27
+ ```
28
+
29
+ 流式:
30
+
31
+ ```
32
+ curl -sS -N -H 'Content-Type: application/json' \
33
+ -X POST http://localhost:5507/v1/chat/completions \
34
+ -d '{
35
+ "model": "Qwen/Qwen3-Coder-480B-A35B-Instruct",
36
+ "messages": [{"role":"user","content":"Stream a short reply."}],
37
+ "stream": true
38
+ }'
39
+ ```
40
+
41
+ 严格 JSON 模式:
42
+
43
+ ```
44
+ curl -i -sS -H 'Content-Type: application/json' \
45
+ -X POST http://localhost:5507/v1/chat/completions \
46
+ -d '{
47
+ "model": "Qwen/Qwen3-Coder-480B-A35B-Instruct",
48
+ "messages": [{"role":"user","content":"只返回一个JSON对象:{\"ok\":true}"}],
49
+ "response_format": { "type": "json_object" },
50
+ "stream": false
51
+ }'
52
+ ```
53
+
54
+ ## 日志与追踪
55
+
56
+ - 运行日志:`server-modelscope.log`
57
+ - DebugCenter:`~/.routecodex/logs/debug-center.log`
58
+ - 关联方式:使用响应头 `x-request-id` 在日志中检索对应请求链路
59
+
@@ -0,0 +1,60 @@
1
+ # RouteCodex 验证配置集合
2
+
3
+ 本目录包含经过端到端测试验证的 RouteCodex 配置文件,按版本组织。
4
+
5
+ ## 版本历史
6
+
7
+ ### v0.45.0 (当前版本)
8
+ **验证日期**: 2025-10-13T01:56:00Z
9
+ **验证状态**: ✅ 通过 - LM Studio + Qwen Provider 集成验证成功
10
+
11
+ #### 配置文件
12
+ - `lmstudio-5521-gpt-oss-20b-mlx.json` - LM Studio 用户配置 (端口 5521)
13
+ - `merged-config.5521.json` - 系统合并后的完整配置
14
+ - `qwen-5522-qwen3-coder-plus.json` - Qwen 用户配置 (端口 5522)
15
+ - `merged-config.qwen-5522.json` - Qwen 系统合并配置
16
+ - `README.md` - 详细验证报告
17
+
18
+ #### 验证环境
19
+ - **分支**: feat/new-feature
20
+ - **模型**: gpt-oss-20b-mlx
21
+ - **LM Studio**: localhost:1234
22
+ - **协议支持**: OpenAI + Anthropic
23
+
24
+ #### 使用方法
25
+ ```bash
26
+ # 启动 LM Studio 配置 (端口 5521)
27
+ npx ts-node src/cli.ts start --config ~/.routecodex/config/lmstudio-5521-gpt-oss-20b-mlx.json --port 5521
28
+
29
+ # 启动 Qwen Provider 配置 (端口 5522)
30
+ npx ts-node src/cli.ts start --config ~/.routecodex/config/qwen-5522-qwen3-coder-plus.json --port 5522
31
+ ```
32
+
33
+ ## 目录结构
34
+ ```
35
+ docs/verified-configs/
36
+ ├── README.md # 本文件
37
+ └── v0.45.0/ # 版本化配置目录
38
+ ├── lmstudio-5521-gpt-oss-20b-mlx.json
39
+ ├── merged-config.5521.json
40
+ └── README.md # 详细验证报告
41
+ ```
42
+
43
+ ## 验证标准
44
+
45
+ 每个版本的配置都必须通过以下验证:
46
+
47
+ 1. **✅ 配置加载系统** - 用户配置正确加载
48
+ 2. **✅ 4层管道架构** - LLM Switch, Compatibility, Provider, AI Service
49
+ 3. **✅ 动态路由分类** - 9种路由类别配置正确
50
+ 4. **✅ 服务集成** - 目标服务连接测试通过
51
+ 5. **✅ 协议支持** - OpenAI 和 Anthropic 协议端点
52
+ 6. **✅ 功能测试** - 基本请求/响应流程验证
53
+
54
+ ## 版本管理策略
55
+
56
+ - **主版本** (Major): 重大架构变更,配置可能不兼容
57
+ - **次版本** (Minor): 新功能添加,保持向后兼容
58
+ - **修订版本** (Patch): Bug修复,配置格式不变
59
+
60
+ 每个验证过的配置都绑定到特定的 RouteCodex 版本,确保兼容性。