@tonyclaw/agent-inspector 4.0.1 → 4.0.3

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 (373) hide show
  1. package/.output/backend/nitro.json +1 -1
  2. package/.output/cli.js +193 -110
  3. package/.output/server/_ssr/index.mjs +1 -1
  4. package/.output/server/_ssr/{router-CTHqmroT.mjs → router-ChILzhmz.mjs} +92 -4
  5. package/.output/server/index.mjs +1 -1
  6. package/.output/ui/assets/{CompareDrawer-L3n4J-Or.js → CompareDrawer-Co3cUF_I.js} +1 -1
  7. package/.output/ui/assets/{InspectorPet-D5o_3OZS.js → InspectorPet-jFcrL37X.js} +1 -1
  8. package/.output/ui/assets/{ProxyViewerContainer-Ocagx75S.js → ProxyViewerContainer-BPzt_VpM.js} +4 -4
  9. package/.output/ui/assets/{ReplayDialog-Bk7x1h-y.js → ReplayDialog-C6O_zuwI.js} +1 -1
  10. package/.output/ui/assets/{RequestAnatomy-U4lzL7Sc.js → RequestAnatomy-Ca6NvB7L.js} +1 -1
  11. package/.output/ui/assets/{ResponseView-LOWfvBLK.js → ResponseView-BzqKcveJ.js} +1 -1
  12. package/.output/ui/assets/{StreamingChunkSequence-DPfsrrXQ.js → StreamingChunkSequence-9pCZIsS_.js} +1 -1
  13. package/.output/ui/assets/{_sessionId-0MlWS-CO.js → _sessionId-BMP3KVGR.js} +1 -1
  14. package/.output/ui/assets/{_sessionId-OdX2Jvt1.js → _sessionId-y4eRoT1H.js} +1 -1
  15. package/.output/ui/assets/{index-Ea-c8hPg.js → index-CH5w-haG.js} +1 -1
  16. package/.output/ui/assets/{index-zVVS53Hd.js → index-CmocEhyU.js} +1 -1
  17. package/.output/ui/assets/{index-Du4qNOOt.js → index-DT8sMJ_n.js} +2 -2
  18. package/.output/ui/assets/{index-gvFj_9K6.js → index-bfsbIRZa.js} +1 -1
  19. package/.output/ui/assets/{json-viewer-C1WAMzg3.js → json-viewer-BfFOSDG5.js} +1 -1
  20. package/.output/ui/assets/{jszip.min-B8AKu2zm.js → jszip.min-BkbVkOsp.js} +1 -1
  21. package/.output/ui/index.html +1 -1
  22. package/package.json +5 -10
  23. package/src/assets/IDE/claudecode-color.svg +0 -1
  24. package/src/assets/IDE/codex-color.svg +0 -1
  25. package/src/assets/IDE/opencode.svg +0 -1
  26. package/src/assets/IDE/xiaomimimo.svg +0 -1
  27. package/src/assets/favicon.svg +0 -21
  28. package/src/assets/logos/alibaba.svg +0 -1
  29. package/src/assets/logos/anthropic.svg +0 -1
  30. package/src/assets/logos/claude-code.svg +0 -4
  31. package/src/assets/logos/deepseek.svg +0 -1
  32. package/src/assets/logos/minimax.jpeg +0 -0
  33. package/src/assets/logos/openai.svg +0 -1
  34. package/src/assets/logos/opencode.svg +0 -4
  35. package/src/assets/logos/qwen.webp +0 -0
  36. package/src/assets/logos/zhipuai.svg +0 -219
  37. package/src/backend/router.tsx +0 -36
  38. package/src/backend/routes/$.ts +0 -26
  39. package/src/backend/routes/__root.ts +0 -4
  40. package/src/backend/routes/api/-instances.ts +0 -7
  41. package/src/backend/routes/api/alerts.summary.ts +0 -28
  42. package/src/backend/routes/api/alerts.ts +0 -70
  43. package/src/backend/routes/api/config.paths.ts +0 -14
  44. package/src/backend/routes/api/config.ts +0 -73
  45. package/src/backend/routes/api/ecosystem.packages.$packageId.help.ts +0 -11
  46. package/src/backend/routes/api/ecosystem.packages.$packageId.install.ts +0 -11
  47. package/src/backend/routes/api/ecosystem.packages.$packageId.runner-presets.ts +0 -11
  48. package/src/backend/routes/api/ecosystem.packages.$packageId.upgrade.ts +0 -11
  49. package/src/backend/routes/api/ecosystem.packages.ts +0 -21
  50. package/src/backend/routes/api/ecosystem.recipes.$recipeId.run.ts +0 -11
  51. package/src/backend/routes/api/ecosystem.tasks.$taskId.ts +0 -16
  52. package/src/backend/routes/api/ecosystem.tasks.ts +0 -12
  53. package/src/backend/routes/api/groups.$groupId.evidence.ts +0 -55
  54. package/src/backend/routes/api/groups.$groupId.sessions.ts +0 -50
  55. package/src/backend/routes/api/groups.$groupId.ts +0 -93
  56. package/src/backend/routes/api/groups.ts +0 -79
  57. package/src/backend/routes/api/health.ts +0 -22
  58. package/src/backend/routes/api/instances.$name.connection.ts +0 -12
  59. package/src/backend/routes/api/instances.$name.restart.ts +0 -23
  60. package/src/backend/routes/api/instances.$name.start.ts +0 -18
  61. package/src/backend/routes/api/instances.$name.stop.ts +0 -23
  62. package/src/backend/routes/api/instances.$name.ts +0 -12
  63. package/src/backend/routes/api/instances.ts +0 -16
  64. package/src/backend/routes/api/knowledge.candidates.$candidateId.promote.ts +0 -32
  65. package/src/backend/routes/api/knowledge.candidates.$candidateId.ts +0 -50
  66. package/src/backend/routes/api/knowledge.candidates.ts +0 -10
  67. package/src/backend/routes/api/knowledge.project-context.ts +0 -29
  68. package/src/backend/routes/api/knowledge.search.ts +0 -62
  69. package/src/backend/routes/api/knowledge.sessions.$sessionId.candidates.ts +0 -26
  70. package/src/backend/routes/api/logs.$id.body.ts +0 -58
  71. package/src/backend/routes/api/logs.$id.chunks.ts +0 -37
  72. package/src/backend/routes/api/logs.$id.replay.ts +0 -297
  73. package/src/backend/routes/api/logs.$id.ts +0 -23
  74. package/src/backend/routes/api/logs.import.ts +0 -39
  75. package/src/backend/routes/api/logs.stream.ts +0 -174
  76. package/src/backend/routes/api/logs.ts +0 -214
  77. package/src/backend/routes/api/mcp.ts +0 -25
  78. package/src/backend/routes/api/models.ts +0 -10
  79. package/src/backend/routes/api/pi-agent.ts +0 -29
  80. package/src/backend/routes/api/providers.$providerId.model-metadata.ts +0 -173
  81. package/src/backend/routes/api/providers.$providerId.test.log.ts +0 -342
  82. package/src/backend/routes/api/providers.$providerId.ts +0 -111
  83. package/src/backend/routes/api/providers.export.ts +0 -44
  84. package/src/backend/routes/api/providers.import.ts +0 -81
  85. package/src/backend/routes/api/providers.scan.ts +0 -28
  86. package/src/backend/routes/api/providers.ts +0 -102
  87. package/src/backend/routes/api/runs.$runId.evidence.ts +0 -55
  88. package/src/backend/routes/api/runs.$runId.ts +0 -50
  89. package/src/backend/routes/api/runs.ts +0 -62
  90. package/src/backend/routes/api/runtime.ts +0 -46
  91. package/src/backend/routes/api/sessions.ts +0 -51
  92. package/src/backend/routes/api/storage.ts +0 -56
  93. package/src/backend/routes/livez.ts +0 -13
  94. package/src/backend/routes/metrics.ts +0 -14
  95. package/src/backend/routes/proxy/$.ts +0 -15
  96. package/src/backend/routes/readyz.ts +0 -18
  97. package/src/backend/start.ts +0 -10
  98. package/src/cli/alias.ts +0 -431
  99. package/src/cli/detect-tools.ts +0 -123
  100. package/src/cli/doctor.ts +0 -836
  101. package/src/cli/instance.ts +0 -1071
  102. package/src/cli/instanceApi.ts +0 -213
  103. package/src/cli/instanceArgs.ts +0 -301
  104. package/src/cli/instanceControl.ts +0 -191
  105. package/src/cli/instanceModel.ts +0 -276
  106. package/src/cli/instanceRegistry.ts +0 -731
  107. package/src/cli/networkHints.ts +0 -170
  108. package/src/cli/onboard.ts +0 -1668
  109. package/src/cli/onboardTarget.ts +0 -228
  110. package/src/cli/rustBackendPackage.ts +0 -458
  111. package/src/cli/startupOutput.ts +0 -16
  112. package/src/cli/templates/codex-skill-onboard.ts +0 -320
  113. package/src/cli/templates/command-onboard.ts +0 -25
  114. package/src/cli/templates/skill-onboard.ts +0 -625
  115. package/src/cli.ts +0 -1433
  116. package/src/components/OnboardingBanner.tsx +0 -115
  117. package/src/components/ProxyViewer.tsx +0 -2259
  118. package/src/components/ProxyViewerContainer.tsx +0 -1076
  119. package/src/components/alerts/AlertsDialog.tsx +0 -615
  120. package/src/components/clients/ClientLogo.tsx +0 -175
  121. package/src/components/ecosystem/AgentLabDialog.tsx +0 -947
  122. package/src/components/errors/SafeErrorBoundary.tsx +0 -201
  123. package/src/components/groups/GroupsDialog.tsx +0 -1304
  124. package/src/components/inspector-pet/InspectorPet.tsx +0 -398
  125. package/src/components/inspector-pet/InspectorPetCrab3D.tsx +0 -455
  126. package/src/components/inspector-pet/inspectorPetLogic.ts +0 -272
  127. package/src/components/pi-agent/PiAgentPanel.tsx +0 -446
  128. package/src/components/pi-agent/piAgentChatLogic.ts +0 -273
  129. package/src/components/providers/ImportWizardDialog.tsx +0 -281
  130. package/src/components/providers/ProviderCard.tsx +0 -347
  131. package/src/components/providers/ProviderForm.tsx +0 -1183
  132. package/src/components/providers/ProviderLogo.tsx +0 -122
  133. package/src/components/providers/ProviderTestResultsView.tsx +0 -734
  134. package/src/components/providers/ProvidersPanel.tsx +0 -714
  135. package/src/components/providers/SettingsDialog.tsx +0 -1042
  136. package/src/components/providers/providerFormCapabilities.ts +0 -36
  137. package/src/components/proxy-viewer/AgentTraceSummary.tsx +0 -902
  138. package/src/components/proxy-viewer/AnswerMarkdown.tsx +0 -51
  139. package/src/components/proxy-viewer/ApplicationBar.tsx +0 -123
  140. package/src/components/proxy-viewer/CompareDrawer.tsx +0 -984
  141. package/src/components/proxy-viewer/ConversationGroup.tsx +0 -208
  142. package/src/components/proxy-viewer/ConversationGroupList.tsx +0 -652
  143. package/src/components/proxy-viewer/ConversationHeader.tsx +0 -429
  144. package/src/components/proxy-viewer/LiveConnectionStatus.tsx +0 -186
  145. package/src/components/proxy-viewer/LogEntry.tsx +0 -1419
  146. package/src/components/proxy-viewer/LogEntryHeader.tsx +0 -596
  147. package/src/components/proxy-viewer/ProviderLogoStack.tsx +0 -57
  148. package/src/components/proxy-viewer/RawExportWarning.tsx +0 -77
  149. package/src/components/proxy-viewer/ReplayDialog.tsx +0 -636
  150. package/src/components/proxy-viewer/RequestToolsPanel.tsx +0 -299
  151. package/src/components/proxy-viewer/ResponseView.tsx +0 -202
  152. package/src/components/proxy-viewer/SessionLoadProgressBar.tsx +0 -61
  153. package/src/components/proxy-viewer/StreamingChunkSequence.tsx +0 -265
  154. package/src/components/proxy-viewer/ThreadConnector.tsx +0 -165
  155. package/src/components/proxy-viewer/ToolTraceEvents.tsx +0 -64
  156. package/src/components/proxy-viewer/TurnGroup.tsx +0 -383
  157. package/src/components/proxy-viewer/TurnGroupList.tsx +0 -156
  158. package/src/components/proxy-viewer/accessibility.ts +0 -8
  159. package/src/components/proxy-viewer/anatomy/RequestAnatomy.tsx +0 -887
  160. package/src/components/proxy-viewer/anatomy/SegmentBar.tsx +0 -222
  161. package/src/components/proxy-viewer/anatomy/contextIntelligence.ts +0 -737
  162. package/src/components/proxy-viewer/anatomy/sessionContextSummary.ts +0 -268
  163. package/src/components/proxy-viewer/anatomy/tokenEstimate.ts +0 -53
  164. package/src/components/proxy-viewer/anatomy/types.ts +0 -41
  165. package/src/components/proxy-viewer/anatomy/useAnatomyJump.ts +0 -114
  166. package/src/components/proxy-viewer/bodyHydration.ts +0 -123
  167. package/src/components/proxy-viewer/cacheTrend.ts +0 -50
  168. package/src/components/proxy-viewer/diff/DiffView.tsx +0 -321
  169. package/src/components/proxy-viewer/diff/computeDiff.ts +0 -178
  170. package/src/components/proxy-viewer/diff/index.ts +0 -3
  171. package/src/components/proxy-viewer/formats/anthropic/ContentBlocks.tsx +0 -194
  172. package/src/components/proxy-viewer/formats/anthropic/ResponseView.tsx +0 -81
  173. package/src/components/proxy-viewer/formats/anthropic/thinkingExtract.ts +0 -21
  174. package/src/components/proxy-viewer/formats/index.tsx +0 -47
  175. package/src/components/proxy-viewer/formats/openai/ResponseView.tsx +0 -442
  176. package/src/components/proxy-viewer/index.ts +0 -9
  177. package/src/components/proxy-viewer/lazy.ts +0 -41
  178. package/src/components/proxy-viewer/liveConnectionState.ts +0 -158
  179. package/src/components/proxy-viewer/log-formats/anthropic.ts +0 -191
  180. package/src/components/proxy-viewer/log-formats/index.ts +0 -23
  181. package/src/components/proxy-viewer/log-formats/openai.ts +0 -256
  182. package/src/components/proxy-viewer/log-formats/types.ts +0 -40
  183. package/src/components/proxy-viewer/log-formats/unknown.ts +0 -18
  184. package/src/components/proxy-viewer/logEntryVisibility.ts +0 -73
  185. package/src/components/proxy-viewer/logFocus.ts +0 -54
  186. package/src/components/proxy-viewer/proxyViewerContainerLogic.ts +0 -124
  187. package/src/components/proxy-viewer/proxyViewerLogic.ts +0 -488
  188. package/src/components/proxy-viewer/replayComparison.ts +0 -131
  189. package/src/components/proxy-viewer/requestDiff.ts +0 -277
  190. package/src/components/proxy-viewer/requestTools.ts +0 -220
  191. package/src/components/proxy-viewer/useCopyFeedback.ts +0 -38
  192. package/src/components/proxy-viewer/useKeyboardNavigation.ts +0 -232
  193. package/src/components/proxy-viewer/viewerState.ts +0 -176
  194. package/src/components/ui/badge.tsx +0 -47
  195. package/src/components/ui/button.tsx +0 -47
  196. package/src/components/ui/collapsible.tsx +0 -21
  197. package/src/components/ui/confirm-dialog.tsx +0 -51
  198. package/src/components/ui/crab-logo.tsx +0 -45
  199. package/src/components/ui/crab-variants.tsx +0 -467
  200. package/src/components/ui/dialog.tsx +0 -130
  201. package/src/components/ui/icon-trigger.ts +0 -2
  202. package/src/components/ui/json-viewer-bulk.ts +0 -132
  203. package/src/components/ui/json-viewer.tsx +0 -508
  204. package/src/components/ui/scroll-area.tsx +0 -54
  205. package/src/components/ui/select.tsx +0 -178
  206. package/src/components/ui/separator.tsx +0 -28
  207. package/src/components/ui/tabs.tsx +0 -88
  208. package/src/components/ui/tooltip.tsx +0 -51
  209. package/src/components/ui/transient-toast.tsx +0 -105
  210. package/src/contracts/anthropic.ts +0 -230
  211. package/src/contracts/index.ts +0 -59
  212. package/src/contracts/json.ts +0 -37
  213. package/src/contracts/log.ts +0 -139
  214. package/src/contracts/openai.ts +0 -267
  215. package/src/index.css +0 -11
  216. package/src/knowledge/candidateStore.ts +0 -94
  217. package/src/knowledge/distiller.ts +0 -98
  218. package/src/knowledge/openclawClient.ts +0 -161
  219. package/src/knowledge/openclawGatewayClient.ts +0 -249
  220. package/src/knowledge/openclawMarkdown.ts +0 -146
  221. package/src/knowledge/redactor.ts +0 -80
  222. package/src/knowledge/types.ts +0 -83
  223. package/src/lib/alertContract.ts +0 -76
  224. package/src/lib/apiClient.ts +0 -166
  225. package/src/lib/apiFormat.ts +0 -29
  226. package/src/lib/backendImplementation.ts +0 -16
  227. package/src/lib/basePath.ts +0 -107
  228. package/src/lib/browserRuntimeContract.ts +0 -124
  229. package/src/lib/browserRuntimeResolver.ts +0 -333
  230. package/src/lib/chunkLoadRecovery.ts +0 -83
  231. package/src/lib/claudeCodeStrip.ts +0 -98
  232. package/src/lib/clipboard.ts +0 -67
  233. package/src/lib/codingAgentEndpoints.ts +0 -54
  234. package/src/lib/ecosystemContract.ts +0 -130
  235. package/src/lib/export-logs.ts +0 -287
  236. package/src/lib/groupContract.ts +0 -166
  237. package/src/lib/instanceContract.ts +0 -239
  238. package/src/lib/jsonFile.ts +0 -46
  239. package/src/lib/logImportContract.ts +0 -12
  240. package/src/lib/managedInstance.ts +0 -112
  241. package/src/lib/mask.ts +0 -4
  242. package/src/lib/objectUtils.ts +0 -22
  243. package/src/lib/piAgentContract.ts +0 -102
  244. package/src/lib/providerContract.ts +0 -125
  245. package/src/lib/providerImportContract.ts +0 -27
  246. package/src/lib/providerModelMetadata.ts +0 -458
  247. package/src/lib/providerTestContract.ts +0 -170
  248. package/src/lib/providerTestPrompt.ts +0 -100
  249. package/src/lib/publicBasePathContext.ts +0 -137
  250. package/src/lib/resourceLimits.ts +0 -345
  251. package/src/lib/runContract.ts +0 -164
  252. package/src/lib/runtimeConfig.ts +0 -43
  253. package/src/lib/safeDiagnostic.ts +0 -38
  254. package/src/lib/safeFetch.ts +0 -508
  255. package/src/lib/serverPort.ts +0 -47
  256. package/src/lib/sessionInfoContract.ts +0 -78
  257. package/src/lib/sessionUrl.ts +0 -46
  258. package/src/lib/ssrfGuard.ts +0 -133
  259. package/src/lib/stopReason.ts +0 -130
  260. package/src/lib/themeMode.ts +0 -41
  261. package/src/lib/timeDisplay.ts +0 -22
  262. package/src/lib/toolTrace.ts +0 -290
  263. package/src/lib/uiScale.ts +0 -117
  264. package/src/lib/unknown.ts +0 -27
  265. package/src/lib/upstreamUrl.ts +0 -150
  266. package/src/lib/useAlerts.ts +0 -82
  267. package/src/lib/useGroupEvidence.ts +0 -37
  268. package/src/lib/useGroups.ts +0 -32
  269. package/src/lib/useOnboarding.ts +0 -93
  270. package/src/lib/useProviders.ts +0 -30
  271. package/src/lib/useStripConfig.ts +0 -154
  272. package/src/lib/useThemeMode.ts +0 -40
  273. package/src/lib/useUiScale.ts +0 -52
  274. package/src/lib/utils.ts +0 -78
  275. package/src/mcp/currentContext.ts +0 -65
  276. package/src/mcp/instanceHandlers.ts +0 -151
  277. package/src/mcp/loopback.ts +0 -88
  278. package/src/mcp/mode.ts +0 -75
  279. package/src/mcp/previewExtractor.ts +0 -233
  280. package/src/mcp/server.ts +0 -2274
  281. package/src/mcp/toolHandlers.ts +0 -1533
  282. package/src/proxy/alerts.ts +0 -664
  283. package/src/proxy/chunkStorage.ts +0 -123
  284. package/src/proxy/config.ts +0 -218
  285. package/src/proxy/constants.ts +0 -66
  286. package/src/proxy/dataDir.ts +0 -147
  287. package/src/proxy/ecosystemExecutionConfirmation.ts +0 -114
  288. package/src/proxy/ecosystemExecutionRoute.ts +0 -116
  289. package/src/proxy/ecosystemRegistry.ts +0 -296
  290. package/src/proxy/ecosystemTasks.ts +0 -415
  291. package/src/proxy/evidenceAnalysis.ts +0 -526
  292. package/src/proxy/evidenceExporter.ts +0 -235
  293. package/src/proxy/formats/anthropic/anthropicProvider.ts +0 -75
  294. package/src/proxy/formats/anthropic/handler.ts +0 -75
  295. package/src/proxy/formats/anthropic/index.ts +0 -13
  296. package/src/proxy/formats/anthropic/register.ts +0 -4
  297. package/src/proxy/formats/anthropic/schemas.ts +0 -6
  298. package/src/proxy/formats/anthropic/stream.ts +0 -205
  299. package/src/proxy/formats/handler.ts +0 -46
  300. package/src/proxy/formats/index.ts +0 -13
  301. package/src/proxy/formats/jsonSchema.ts +0 -2
  302. package/src/proxy/formats/openai/alibabaProvider.ts +0 -34
  303. package/src/proxy/formats/openai/codexMetadata.ts +0 -61
  304. package/src/proxy/formats/openai/handler.ts +0 -133
  305. package/src/proxy/formats/openai/index.ts +0 -33
  306. package/src/proxy/formats/openai/provider.ts +0 -50
  307. package/src/proxy/formats/openai/register.ts +0 -4
  308. package/src/proxy/formats/openai/schemas.ts +0 -25
  309. package/src/proxy/formats/openai/stream.ts +0 -600
  310. package/src/proxy/formats/openai/zhipuProvider.ts +0 -31
  311. package/src/proxy/formats/providerAdapter.ts +0 -50
  312. package/src/proxy/formats/providerRegistry.ts +0 -51
  313. package/src/proxy/formats/providers/index.ts +0 -3
  314. package/src/proxy/formats/registry.ts +0 -65
  315. package/src/proxy/groupEvidenceExporter.ts +0 -371
  316. package/src/proxy/groupStore.ts +0 -336
  317. package/src/proxy/handler.ts +0 -729
  318. package/src/proxy/identityProxy.ts +0 -1842
  319. package/src/proxy/jsonlRecovery.ts +0 -554
  320. package/src/proxy/logBodyChunks.ts +0 -91
  321. package/src/proxy/logFinalizer.ts +0 -777
  322. package/src/proxy/logFinalizer.worker.ts +0 -24
  323. package/src/proxy/logImportUpload.ts +0 -128
  324. package/src/proxy/logImporter.ts +0 -813
  325. package/src/proxy/logIndex.ts +0 -663
  326. package/src/proxy/logSearch.ts +0 -122
  327. package/src/proxy/logger.ts +0 -537
  328. package/src/proxy/openaiOrphanToolStrip.ts +0 -142
  329. package/src/proxy/platformCommands.ts +0 -258
  330. package/src/proxy/privateDataPath.ts +0 -419
  331. package/src/proxy/providerImporters.ts +0 -578
  332. package/src/proxy/providerScanStore.ts +0 -87
  333. package/src/proxy/providerSecretStore.ts +0 -216
  334. package/src/proxy/providers.ts +0 -998
  335. package/src/proxy/rawStreamCapture.ts +0 -342
  336. package/src/proxy/runFailures.ts +0 -94
  337. package/src/proxy/runStore.ts +0 -214
  338. package/src/proxy/runtimeAdmission.ts +0 -55
  339. package/src/proxy/runtimeHealth.ts +0 -221
  340. package/src/proxy/runtimeMetrics.ts +0 -149
  341. package/src/proxy/runtimeShutdown.ts +0 -157
  342. package/src/proxy/schemas.ts +0 -112
  343. package/src/proxy/sessionArchive.ts +0 -479
  344. package/src/proxy/sessionInfo.ts +0 -266
  345. package/src/proxy/sessionProcess.ts +0 -194
  346. package/src/proxy/sessionRuntime.ts +0 -121
  347. package/src/proxy/sessionSupervisor.ts +0 -305
  348. package/src/proxy/sessionWorkerEntry.ts +0 -26
  349. package/src/proxy/shutdownCoordinator.ts +0 -90
  350. package/src/proxy/socketTracker.ts +0 -639
  351. package/src/proxy/sqliteLogIndex.ts +0 -733
  352. package/src/proxy/storageLifecycle.ts +0 -432
  353. package/src/proxy/store.ts +0 -1773
  354. package/src/proxy/streamTiming.ts +0 -31
  355. package/src/proxy/toolSchemaWarnings.ts +0 -529
  356. package/src/proxy/uiAssetServer.ts +0 -106
  357. package/src/proxy/upstream.ts +0 -127
  358. package/src/services/alerts.ts +0 -12
  359. package/src/services/groups.ts +0 -119
  360. package/src/services/piAgent.ts +0 -421
  361. package/src/services/piAgentRetrieval.ts +0 -1180
  362. package/src/services/result.ts +0 -17
  363. package/src/services/runs.ts +0 -76
  364. package/src/ui/bootstrap.ts +0 -167
  365. package/src/ui/index.html +0 -38
  366. package/src/ui/logsStreamClient.ts +0 -20
  367. package/src/ui/main.tsx +0 -13
  368. package/src/ui/public/runtime-config.js +0 -2
  369. package/src/ui/router.tsx +0 -13
  370. package/src/ui/routes/__root.tsx +0 -69
  371. package/src/ui/routes/index.tsx +0 -35
  372. package/src/ui/routes/session/$sessionId.tsx +0 -50
  373. package/src/ui/runtimeDiscovery.ts +0 -50
@@ -1,578 +0,0 @@
1
- import { existsSync, readFileSync } from "node:fs";
2
- import { homedir } from "node:os";
3
- import { join } from "node:path";
4
- import { getProviders } from "./providers";
5
- import { normalizeApiKey } from "./providers";
6
- import type { ProviderConfig } from "../lib/providerContract";
7
- import { isPlainRecord } from "../lib/objectUtils";
8
-
9
- export type ExternalProvider = {
10
- name: string;
11
- apiKey: string;
12
- format: "anthropic" | "openai";
13
- anthropicBaseUrl: string;
14
- openaiBaseUrl: string;
15
- openaiResponsesBaseUrl: string;
16
- models: string[];
17
- sourceTool: "claude-code" | "opencode" | "mimo-code";
18
- alreadyExists: boolean;
19
- };
20
-
21
- const ZHIPU_OPENAI_BASE_URL = "https://open.bigmodel.cn/api/paas/v4";
22
- const ZHIPU_CODING_OPENAI_BASE_URL = "https://open.bigmodel.cn/api/coding/paas/v4";
23
- const ZHIPU_CODING_ANTHROPIC_BASE_URL = "https://open.bigmodel.cn/api/anthropic";
24
- const MINIMAX_OPENAI_BASE_URL = "https://api.minimaxi.com";
25
-
26
- function defaultOpenAIResponsesBaseUrl(providerId: string): string {
27
- const normalized = providerId.toLowerCase();
28
- return normalized === "minimax" || normalized.startsWith("minimax-")
29
- ? MINIMAX_OPENAI_BASE_URL
30
- : "";
31
- }
32
-
33
- function openAIResponsesBaseUrlMatchesExisting(
34
- provider: ProviderConfig,
35
- externalProvider: ExternalProvider,
36
- ): boolean {
37
- const existingUrl = provider.openaiResponsesBaseUrl ?? "";
38
- if (existingUrl === externalProvider.openaiResponsesBaseUrl) return true;
39
-
40
- const defaultUrl = defaultOpenAIResponsesBaseUrl(externalProvider.name);
41
- if (defaultUrl === "") return false;
42
-
43
- return (
44
- (existingUrl === "" && externalProvider.openaiResponsesBaseUrl === defaultUrl) ||
45
- (existingUrl === defaultUrl && externalProvider.openaiResponsesBaseUrl === "")
46
- );
47
- }
48
-
49
- function readJsonSafe(filePath: string): Record<string, unknown> | null {
50
- try {
51
- if (!existsSync(filePath)) return null;
52
- const raw = readFileSync(filePath, "utf-8");
53
- const parsed: unknown = JSON.parse(raw);
54
- return isPlainRecord(parsed) ? parsed : null;
55
- } catch {
56
- return null;
57
- }
58
- }
59
-
60
- function getEnvValue(envObj: unknown, key: string): string | undefined {
61
- if (!isPlainRecord(envObj)) return undefined;
62
- const val = envObj[key];
63
- return typeof val === "string" ? val.trim() : undefined;
64
- }
65
-
66
- // Map of well-known API hostnames to their proper brand names.
67
- // The key is the domain (second-level domain extracted from the hostname),
68
- // matched case-insensitively.
69
- const KNOWN_PROVIDER_NAMES: Record<string, string> = {
70
- deepseek: "DeepSeek",
71
- minimaxi: "MiniMax",
72
- openai: "OpenAI",
73
- anthropic: "Anthropic",
74
- openrouter: "OpenRouter",
75
- groq: "Groq",
76
- together: "Together",
77
- fireworks: "Fireworks",
78
- bedrock: "Bedrock",
79
- vertexai: "Vertex AI",
80
- azure: "Azure",
81
- moonshot: "Moonshot",
82
- zhipu: "ZhipuAI",
83
- zhipuai: "ZhipuAI",
84
- bigmodel: "ZhipuAI",
85
- zai: "Z.AI",
86
- qwen: "Qwen",
87
- baichuan: "Baichuan",
88
- iflytek: "iFlytek",
89
- doubao: "Doubao",
90
- lingyiwanwu: "LingyiWanwu",
91
- stepfun: "StepFun",
92
- };
93
-
94
- function deriveNameFromUrl(url: string): string {
95
- try {
96
- const hostname = new URL(url).hostname;
97
- const parts = hostname.split(".");
98
- const domain = parts.length >= 2 ? (parts[parts.length - 2] ?? hostname) : hostname;
99
- const domainLower = domain.toLowerCase();
100
- // Check known providers first
101
- if (KNOWN_PROVIDER_NAMES[domainLower] !== undefined) {
102
- return KNOWN_PROVIDER_NAMES[domainLower];
103
- }
104
- return domain.charAt(0).toUpperCase() + domain.slice(1);
105
- } catch {
106
- return "Imported Provider";
107
- }
108
- }
109
-
110
- // ── Claude Code ──────────────────────────────────────────
111
-
112
- function detectClaudeCodeProviders(): ExternalProvider[] {
113
- const home = homedir();
114
- const results: ExternalProvider[] = [];
115
-
116
- // Read global + local settings, local takes precedence
117
- const globalConfig = readJsonSafe(join(home, ".claude", "settings.json"));
118
- const localConfig = readJsonSafe(join(home, ".claude", "settings.local.json"));
119
-
120
- const mergedEnv: Record<string, unknown> = {};
121
- if (isPlainRecord(globalConfig)) {
122
- const env = globalConfig["env"];
123
- if (isPlainRecord(env)) {
124
- Object.assign(mergedEnv, env);
125
- }
126
- }
127
- if (isPlainRecord(localConfig)) {
128
- const env = localConfig["env"];
129
- if (isPlainRecord(env)) {
130
- Object.assign(mergedEnv, env);
131
- }
132
- }
133
-
134
- const baseUrl = getEnvValue(mergedEnv, "ANTHROPIC_BASE_URL");
135
- const authToken =
136
- getEnvValue(mergedEnv, "ANTHROPIC_AUTH_TOKEN") ?? getEnvValue(mergedEnv, "ANTHROPIC_API_KEY");
137
-
138
- if (baseUrl === undefined || baseUrl === "" || authToken === undefined || authToken === "") {
139
- return results;
140
- }
141
-
142
- // Collect unique models
143
- const modelSet = new Set<string>();
144
- const modelKeys = [
145
- "ANTHROPIC_MODEL",
146
- "ANTHROPIC_DEFAULT_OPUS_MODEL",
147
- "ANTHROPIC_DEFAULT_SONNET_MODEL",
148
- "ANTHROPIC_DEFAULT_HAIKU_MODEL",
149
- ];
150
- for (const key of modelKeys) {
151
- const val = getEnvValue(mergedEnv, key);
152
- if (val !== undefined && val !== "") modelSet.add(val);
153
- }
154
- const models = modelSet.size > 0 ? [...modelSet] : ["default"];
155
-
156
- results.push({
157
- name: deriveNameFromUrl(baseUrl),
158
- apiKey: normalizeApiKey(authToken),
159
- format: "anthropic",
160
- anthropicBaseUrl: baseUrl,
161
- openaiBaseUrl: "",
162
- openaiResponsesBaseUrl: "",
163
- models,
164
- sourceTool: "claude-code",
165
- alreadyExists: false, // filled in later
166
- });
167
-
168
- return results;
169
- }
170
-
171
- // ── OpenCode ─────────────────────────────────────────────
172
-
173
- function detectOpenCodeProviders(): ExternalProvider[] {
174
- const home = homedir();
175
- const results: ExternalProvider[] = [];
176
-
177
- const config = readJsonSafe(join(home, ".config", "opencode", "opencode.json"));
178
- if (config === null) return results;
179
-
180
- // Read auth.json (separate credentials file)
181
- const auth = readJsonSafe(join(home, ".local", "share", "opencode", "auth.json"));
182
-
183
- const providersVal = config["provider"];
184
- if (!isPlainRecord(providersVal)) {
185
- return results;
186
- }
187
- const providers: Record<string, unknown> = providersVal;
188
-
189
- for (const [providerId, providerObj] of Object.entries(providers)) {
190
- if (!isPlainRecord(providerObj)) continue;
191
-
192
- const options = providerObj["options"];
193
- const npm: unknown = providerObj["npm"];
194
- const npmStr = typeof npm === "string" ? npm : "";
195
- const format: "anthropic" | "openai" = npmStr === "@ai-sdk/anthropic" ? "anthropic" : "openai";
196
-
197
- let baseURL = "";
198
- let apiKey = "";
199
- if (isPlainRecord(options)) {
200
- baseURL = typeof options["baseURL"] === "string" ? options["baseURL"].trim() : "";
201
- apiKey = typeof options["apiKey"] === "string" ? options["apiKey"].trim() : "";
202
- }
203
-
204
- // Resolve apiKey: prefer inline, fallback to auth.json
205
- if (apiKey === "" && isPlainRecord(auth)) {
206
- const cred = auth[providerId];
207
- if (isPlainRecord(cred)) {
208
- const key: unknown = cred["key"];
209
- if (typeof key === "string" && key !== "") apiKey = key;
210
- }
211
- }
212
-
213
- if (baseURL === "" || apiKey === "") continue;
214
-
215
- // Collect models
216
- const modelSet = new Set<string>();
217
- const modelsObj = providerObj["models"];
218
-
219
- if (isPlainRecord(modelsObj)) {
220
- for (const [modelId, modelDef] of Object.entries(modelsObj)) {
221
- if (typeof modelDef === "string") {
222
- modelSet.add(modelDef);
223
- } else if (isPlainRecord(modelDef)) {
224
- // modelId is the actual model identifier sent to the remote API
225
- modelSet.add(modelId);
226
- } else {
227
- modelSet.add(modelId);
228
- }
229
- }
230
- }
231
- const models = modelSet.size > 0 ? [...modelSet] : ["default"];
232
-
233
- results.push({
234
- name: providerId,
235
- apiKey: normalizeApiKey(apiKey),
236
- format,
237
- anthropicBaseUrl: format === "anthropic" ? baseURL : "",
238
- openaiBaseUrl: format === "openai" ? baseURL : "",
239
- openaiResponsesBaseUrl: defaultOpenAIResponsesBaseUrl(providerId),
240
- models,
241
- sourceTool: "opencode",
242
- alreadyExists: false,
243
- });
244
- }
245
-
246
- return results;
247
- }
248
-
249
- // ── MiMo Code ────────────────────────────────────────────
250
-
251
- function stripJsoncComments(raw: string): string {
252
- let result = "";
253
- let i = 0;
254
- let inString = false;
255
- let stringChar = "";
256
-
257
- while (i < raw.length) {
258
- const ch = raw[i];
259
- const next = raw[i + 1];
260
-
261
- if (inString) {
262
- if (ch === "\\" && next !== undefined) {
263
- result += ch + next;
264
- i += 2;
265
- continue;
266
- }
267
- if (ch === stringChar) {
268
- inString = false;
269
- stringChar = "";
270
- }
271
- result += ch;
272
- i += 1;
273
- continue;
274
- }
275
-
276
- if (ch === '"' || ch === "'") {
277
- inString = true;
278
- stringChar = ch;
279
- result += ch;
280
- i += 1;
281
- continue;
282
- }
283
-
284
- if (ch === "/" && next === "/") {
285
- while (i < raw.length && raw[i] !== "\n") {
286
- i += 1;
287
- }
288
- continue;
289
- }
290
-
291
- if (ch === "/" && next === "*") {
292
- i += 2;
293
- while (i < raw.length - 1 && !(raw[i] === "*" && raw[i + 1] === "/")) {
294
- i += 1;
295
- }
296
- i += 2;
297
- continue;
298
- }
299
-
300
- result += ch;
301
- i += 1;
302
- }
303
-
304
- return result;
305
- }
306
-
307
- function readJsonCSafe(filePath: string): Record<string, unknown> | null {
308
- try {
309
- if (!existsSync(filePath)) return null;
310
- const raw = readFileSync(filePath, "utf-8");
311
- const stripped = stripJsoncComments(raw);
312
- const parsed: unknown = JSON.parse(stripped);
313
- return isPlainRecord(parsed) ? parsed : null;
314
- } catch {
315
- return null;
316
- }
317
- }
318
-
319
- function detectMiMoCodeProviders(): ExternalProvider[] {
320
- const home = homedir();
321
- const results: ExternalProvider[] = [];
322
-
323
- const config =
324
- readJsonCSafe(join(home, ".config", "mimocode", "mimocode.jsonc")) ??
325
- readJsonCSafe(join(home, ".config", "mimocode", "mimocode.json")) ??
326
- readJsonCSafe(join(home, ".config", "mimocode", "config.jsonc")) ??
327
- readJsonCSafe(join(home, ".config", "mimocode", "config.json")) ??
328
- readJsonCSafe(join(home, ".mimocode", "config.jsonc")) ??
329
- readJsonCSafe(join(home, ".mimocode", "config.json"));
330
-
331
- const auth = readJsonSafe(join(home, ".local", "share", "mimocode", "auth.json"));
332
-
333
- // Process providers from config (if config exists and has a provider section)
334
- const providersVal = config?.["provider"];
335
- const configProviders: Record<string, unknown> = isPlainRecord(providersVal) ? providersVal : {};
336
-
337
- for (const [providerId, providerObj] of Object.entries(configProviders)) {
338
- if (!isPlainRecord(providerObj)) continue;
339
-
340
- const options = providerObj["options"];
341
- const npm: unknown = providerObj["npm"];
342
- const npmStr = typeof npm === "string" ? npm : "";
343
- const format: "anthropic" | "openai" = npmStr === "@ai-sdk/anthropic" ? "anthropic" : "openai";
344
-
345
- let baseURL = "";
346
- let apiKey = "";
347
- if (isPlainRecord(options)) {
348
- baseURL = typeof options["baseURL"] === "string" ? options["baseURL"].trim() : "";
349
- apiKey = typeof options["apiKey"] === "string" ? options["apiKey"].trim() : "";
350
- }
351
-
352
- if (apiKey === "" && isPlainRecord(auth)) {
353
- const cred = auth[providerId];
354
- if (isPlainRecord(cred)) {
355
- const key: unknown = cred["key"];
356
- if (typeof key === "string" && key !== "") apiKey = key;
357
- }
358
- }
359
-
360
- if (baseURL === "" || apiKey === "") continue;
361
-
362
- const modelSet = new Set<string>();
363
- const modelsObj = providerObj["models"];
364
-
365
- if (isPlainRecord(modelsObj)) {
366
- for (const [modelId, modelDef] of Object.entries(modelsObj)) {
367
- if (typeof modelDef === "string") {
368
- modelSet.add(modelDef);
369
- } else if (isPlainRecord(modelDef)) {
370
- modelSet.add(modelId);
371
- } else {
372
- modelSet.add(modelId);
373
- }
374
- }
375
- }
376
- const models = modelSet.size > 0 ? [...modelSet] : ["default"];
377
-
378
- results.push({
379
- name: providerId,
380
- apiKey: normalizeApiKey(apiKey),
381
- format,
382
- anthropicBaseUrl: format === "anthropic" ? baseURL : "",
383
- openaiBaseUrl: format === "openai" ? baseURL : "",
384
- openaiResponsesBaseUrl: defaultOpenAIResponsesBaseUrl(providerId),
385
- models,
386
- sourceTool: "mimo-code",
387
- alreadyExists: false,
388
- });
389
- }
390
-
391
- // Scan orphan auth.json entries not referenced in config
392
- if (isPlainRecord(auth)) {
393
- const knownDefaults: Record<
394
- string,
395
- {
396
- anthropicBaseUrl: string;
397
- openaiBaseUrl: string;
398
- openaiResponsesBaseUrl?: string;
399
- format: "anthropic" | "openai";
400
- }
401
- > = {
402
- deepseek: {
403
- anthropicBaseUrl: "https://api.deepseek.com/anthropic",
404
- openaiBaseUrl: "https://api.deepseek.com",
405
- format: "anthropic",
406
- },
407
- minimax: {
408
- anthropicBaseUrl: "https://api.minimaxi.com/anthropic",
409
- openaiBaseUrl: MINIMAX_OPENAI_BASE_URL,
410
- openaiResponsesBaseUrl: MINIMAX_OPENAI_BASE_URL,
411
- format: "anthropic",
412
- },
413
- "minimax-coding-plan": {
414
- anthropicBaseUrl: "https://api.minimaxi.com/anthropic",
415
- openaiBaseUrl: MINIMAX_OPENAI_BASE_URL,
416
- openaiResponsesBaseUrl: MINIMAX_OPENAI_BASE_URL,
417
- format: "anthropic",
418
- },
419
- openai: {
420
- anthropicBaseUrl: "",
421
- openaiBaseUrl: "https://api.openai.com",
422
- format: "openai",
423
- },
424
- anthropic: {
425
- anthropicBaseUrl: "https://api.anthropic.com",
426
- openaiBaseUrl: "",
427
- format: "anthropic",
428
- },
429
- groq: {
430
- anthropicBaseUrl: "",
431
- openaiBaseUrl: "https://api.groq.com/openai",
432
- format: "openai",
433
- },
434
- openrouter: {
435
- anthropicBaseUrl: "",
436
- openaiBaseUrl: "https://openrouter.ai/api",
437
- format: "openai",
438
- },
439
- together: {
440
- anthropicBaseUrl: "",
441
- openaiBaseUrl: "https://api.together.xyz",
442
- format: "openai",
443
- },
444
- zhipu: {
445
- anthropicBaseUrl: "",
446
- openaiBaseUrl: ZHIPU_OPENAI_BASE_URL,
447
- format: "openai",
448
- },
449
- zhipuai: {
450
- anthropicBaseUrl: "",
451
- openaiBaseUrl: ZHIPU_OPENAI_BASE_URL,
452
- format: "openai",
453
- },
454
- bigmodel: {
455
- anthropicBaseUrl: "",
456
- openaiBaseUrl: ZHIPU_OPENAI_BASE_URL,
457
- format: "openai",
458
- },
459
- zai: {
460
- anthropicBaseUrl: "",
461
- openaiBaseUrl: ZHIPU_OPENAI_BASE_URL,
462
- format: "openai",
463
- },
464
- glm: {
465
- anthropicBaseUrl: ZHIPU_CODING_ANTHROPIC_BASE_URL,
466
- openaiBaseUrl: ZHIPU_CODING_OPENAI_BASE_URL,
467
- format: "anthropic",
468
- },
469
- "glm-coding-plan": {
470
- anthropicBaseUrl: ZHIPU_CODING_ANTHROPIC_BASE_URL,
471
- openaiBaseUrl: ZHIPU_CODING_OPENAI_BASE_URL,
472
- format: "anthropic",
473
- },
474
- "zhipu-coding-plan": {
475
- anthropicBaseUrl: ZHIPU_CODING_ANTHROPIC_BASE_URL,
476
- openaiBaseUrl: ZHIPU_CODING_OPENAI_BASE_URL,
477
- format: "anthropic",
478
- },
479
- "zai-coding-plan": {
480
- anthropicBaseUrl: ZHIPU_CODING_ANTHROPIC_BASE_URL,
481
- openaiBaseUrl: ZHIPU_CODING_OPENAI_BASE_URL,
482
- format: "anthropic",
483
- },
484
- };
485
-
486
- for (const [key, cred] of Object.entries(auth)) {
487
- if (configProviders[key] !== undefined) continue;
488
- if (!isPlainRecord(cred)) continue;
489
- const apiKey: unknown = cred["key"];
490
- if (typeof apiKey !== "string" || apiKey === "") continue;
491
-
492
- let defaults = knownDefaults[key.toLowerCase()];
493
- if (defaults === undefined) {
494
- for (const [knownKey, cfg] of Object.entries(knownDefaults)) {
495
- if (key.toLowerCase().startsWith(knownKey)) {
496
- defaults = cfg;
497
- break;
498
- }
499
- }
500
- }
501
- if (defaults === undefined) continue;
502
-
503
- results.push({
504
- name: key,
505
- apiKey: normalizeApiKey(apiKey),
506
- format: defaults.format,
507
- anthropicBaseUrl: defaults.anthropicBaseUrl,
508
- openaiBaseUrl: defaults.openaiBaseUrl,
509
- openaiResponsesBaseUrl:
510
- defaults.openaiResponsesBaseUrl ?? defaultOpenAIResponsesBaseUrl(key),
511
- models: ["default"],
512
- sourceTool: "mimo-code",
513
- alreadyExists: false,
514
- });
515
- }
516
- }
517
-
518
- return results;
519
- }
520
-
521
- // ── Combined scanner ─────────────────────────────────────
522
-
523
- export function scanExternalProviders(): { providers: ExternalProvider[]; warnings: string[] } {
524
- const warnings: string[] = [];
525
-
526
- let claudeProviders: ExternalProvider[] = [];
527
- try {
528
- claudeProviders = detectClaudeCodeProviders();
529
- } catch (err) {
530
- warnings.push(`Claude Code: ${err instanceof Error ? err.message : String(err)}`);
531
- }
532
-
533
- let opencodeProviders: ExternalProvider[] = [];
534
- try {
535
- opencodeProviders = detectOpenCodeProviders();
536
- } catch (err) {
537
- warnings.push(`OpenCode: ${err instanceof Error ? err.message : String(err)}`);
538
- }
539
-
540
- let mimoProviders: ExternalProvider[] = [];
541
- try {
542
- mimoProviders = detectMiMoCodeProviders();
543
- } catch (err) {
544
- warnings.push(`MiMo Code: ${err instanceof Error ? err.message : String(err)}`);
545
- }
546
-
547
- const allProviders = [...claudeProviders, ...opencodeProviders, ...mimoProviders];
548
-
549
- // Filter out providers already using the localhost proxy (already switched)
550
- const filteredProviders = allProviders.filter((p) => {
551
- const url = p.anthropicBaseUrl || p.openaiBaseUrl || p.openaiResponsesBaseUrl;
552
- return !/(?:localhost|127\.0\.0\.1)/.test(url);
553
- });
554
-
555
- // Mark already-existing providers (same apiKey + format-specific baseUrl)
556
- let existing: ProviderConfig[] = [];
557
- try {
558
- existing = getProviders();
559
- } catch {
560
- // If we can't load existing providers, just skip the duplicate check
561
- }
562
-
563
- for (const ext of filteredProviders) {
564
- ext.alreadyExists = existing.some((p) => {
565
- if (p.apiKey !== ext.apiKey) return false;
566
- // Match on the format-specific base URL (external providers only set one)
567
- if (ext.format === "anthropic") {
568
- return (p.anthropicBaseUrl ?? "") === ext.anthropicBaseUrl;
569
- }
570
- return (
571
- (p.openaiBaseUrl ?? "") === ext.openaiBaseUrl &&
572
- openAIResponsesBaseUrlMatchesExisting(p, ext)
573
- );
574
- });
575
- }
576
-
577
- return { providers: filteredProviders, warnings };
578
- }
@@ -1,87 +0,0 @@
1
- import { randomUUID } from "node:crypto";
2
- import { maskApiKey } from "../lib/mask";
3
- import type { ScannedProviderDto } from "../lib/providerImportContract";
4
- import type { ExternalProvider } from "./providerImporters";
5
-
6
- const SCAN_TTL_MS = 5 * 60 * 1000;
7
- const MAX_ACTIVE_SCANS = 8;
8
- const MAX_SCANNED_PROVIDERS = 100;
9
-
10
- type ProviderScanSession = {
11
- expiresAt: number;
12
- providers: ReadonlyMap<string, ExternalProvider>;
13
- };
14
-
15
- const sessions = new Map<string, ProviderScanSession>();
16
-
17
- function removeExpired(now: number): void {
18
- for (const [scanId, session] of sessions) {
19
- if (session.expiresAt <= now) sessions.delete(scanId);
20
- }
21
- }
22
-
23
- function enforceSessionLimit(): void {
24
- while (sessions.size >= MAX_ACTIVE_SCANS) {
25
- const oldest = sessions.keys().next().value;
26
- if (typeof oldest !== "string") return;
27
- sessions.delete(oldest);
28
- }
29
- }
30
-
31
- export function createProviderScan(
32
- providers: readonly ExternalProvider[],
33
- now = Date.now(),
34
- ): { scanId: string; providers: ScannedProviderDto[] } {
35
- removeExpired(now);
36
- enforceSessionLimit();
37
-
38
- const scanId = randomUUID();
39
- const providerMap = new Map<string, ExternalProvider>();
40
- const redacted: ScannedProviderDto[] = [];
41
- for (const provider of providers.slice(0, MAX_SCANNED_PROVIDERS)) {
42
- const selectionId = randomUUID();
43
- providerMap.set(selectionId, provider);
44
- redacted.push({
45
- selectionId,
46
- name: provider.name,
47
- apiKeyHint: maskApiKey(provider.apiKey),
48
- format: provider.format,
49
- anthropicBaseUrl: provider.anthropicBaseUrl,
50
- openaiBaseUrl: provider.openaiBaseUrl,
51
- openaiResponsesBaseUrl: provider.openaiResponsesBaseUrl,
52
- models: provider.models,
53
- sourceTool: provider.sourceTool,
54
- alreadyExists: provider.alreadyExists,
55
- });
56
- }
57
-
58
- sessions.set(scanId, {
59
- expiresAt: now + SCAN_TTL_MS,
60
- providers: providerMap,
61
- });
62
- return { scanId, providers: redacted };
63
- }
64
-
65
- export function consumeProviderScan(
66
- scanId: string,
67
- selectionIds: readonly string[],
68
- now = Date.now(),
69
- ): ExternalProvider[] | null {
70
- removeExpired(now);
71
- const session = sessions.get(scanId);
72
- if (session === undefined) return null;
73
- sessions.delete(scanId);
74
-
75
- const uniqueIds = new Set(selectionIds);
76
- const selected: ExternalProvider[] = [];
77
- for (const selectionId of uniqueIds) {
78
- const provider = session.providers.get(selectionId);
79
- if (provider === undefined) return null;
80
- selected.push(provider);
81
- }
82
- return selected;
83
- }
84
-
85
- export function _resetProviderScanStoreForTests(): void {
86
- sessions.clear();
87
- }