@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.
- package/.output/backend/nitro.json +1 -1
- package/.output/cli.js +193 -110
- package/.output/server/_ssr/index.mjs +1 -1
- package/.output/server/_ssr/{router-CTHqmroT.mjs → router-ChILzhmz.mjs} +92 -4
- package/.output/server/index.mjs +1 -1
- package/.output/ui/assets/{CompareDrawer-L3n4J-Or.js → CompareDrawer-Co3cUF_I.js} +1 -1
- package/.output/ui/assets/{InspectorPet-D5o_3OZS.js → InspectorPet-jFcrL37X.js} +1 -1
- package/.output/ui/assets/{ProxyViewerContainer-Ocagx75S.js → ProxyViewerContainer-BPzt_VpM.js} +4 -4
- package/.output/ui/assets/{ReplayDialog-Bk7x1h-y.js → ReplayDialog-C6O_zuwI.js} +1 -1
- package/.output/ui/assets/{RequestAnatomy-U4lzL7Sc.js → RequestAnatomy-Ca6NvB7L.js} +1 -1
- package/.output/ui/assets/{ResponseView-LOWfvBLK.js → ResponseView-BzqKcveJ.js} +1 -1
- package/.output/ui/assets/{StreamingChunkSequence-DPfsrrXQ.js → StreamingChunkSequence-9pCZIsS_.js} +1 -1
- package/.output/ui/assets/{_sessionId-0MlWS-CO.js → _sessionId-BMP3KVGR.js} +1 -1
- package/.output/ui/assets/{_sessionId-OdX2Jvt1.js → _sessionId-y4eRoT1H.js} +1 -1
- package/.output/ui/assets/{index-Ea-c8hPg.js → index-CH5w-haG.js} +1 -1
- package/.output/ui/assets/{index-zVVS53Hd.js → index-CmocEhyU.js} +1 -1
- package/.output/ui/assets/{index-Du4qNOOt.js → index-DT8sMJ_n.js} +2 -2
- package/.output/ui/assets/{index-gvFj_9K6.js → index-bfsbIRZa.js} +1 -1
- package/.output/ui/assets/{json-viewer-C1WAMzg3.js → json-viewer-BfFOSDG5.js} +1 -1
- package/.output/ui/assets/{jszip.min-B8AKu2zm.js → jszip.min-BkbVkOsp.js} +1 -1
- package/.output/ui/index.html +1 -1
- package/package.json +5 -10
- package/src/assets/IDE/claudecode-color.svg +0 -1
- package/src/assets/IDE/codex-color.svg +0 -1
- package/src/assets/IDE/opencode.svg +0 -1
- package/src/assets/IDE/xiaomimimo.svg +0 -1
- package/src/assets/favicon.svg +0 -21
- package/src/assets/logos/alibaba.svg +0 -1
- package/src/assets/logos/anthropic.svg +0 -1
- package/src/assets/logos/claude-code.svg +0 -4
- package/src/assets/logos/deepseek.svg +0 -1
- package/src/assets/logos/minimax.jpeg +0 -0
- package/src/assets/logos/openai.svg +0 -1
- package/src/assets/logos/opencode.svg +0 -4
- package/src/assets/logos/qwen.webp +0 -0
- package/src/assets/logos/zhipuai.svg +0 -219
- package/src/backend/router.tsx +0 -36
- package/src/backend/routes/$.ts +0 -26
- package/src/backend/routes/__root.ts +0 -4
- package/src/backend/routes/api/-instances.ts +0 -7
- package/src/backend/routes/api/alerts.summary.ts +0 -28
- package/src/backend/routes/api/alerts.ts +0 -70
- package/src/backend/routes/api/config.paths.ts +0 -14
- package/src/backend/routes/api/config.ts +0 -73
- package/src/backend/routes/api/ecosystem.packages.$packageId.help.ts +0 -11
- package/src/backend/routes/api/ecosystem.packages.$packageId.install.ts +0 -11
- package/src/backend/routes/api/ecosystem.packages.$packageId.runner-presets.ts +0 -11
- package/src/backend/routes/api/ecosystem.packages.$packageId.upgrade.ts +0 -11
- package/src/backend/routes/api/ecosystem.packages.ts +0 -21
- package/src/backend/routes/api/ecosystem.recipes.$recipeId.run.ts +0 -11
- package/src/backend/routes/api/ecosystem.tasks.$taskId.ts +0 -16
- package/src/backend/routes/api/ecosystem.tasks.ts +0 -12
- package/src/backend/routes/api/groups.$groupId.evidence.ts +0 -55
- package/src/backend/routes/api/groups.$groupId.sessions.ts +0 -50
- package/src/backend/routes/api/groups.$groupId.ts +0 -93
- package/src/backend/routes/api/groups.ts +0 -79
- package/src/backend/routes/api/health.ts +0 -22
- package/src/backend/routes/api/instances.$name.connection.ts +0 -12
- package/src/backend/routes/api/instances.$name.restart.ts +0 -23
- package/src/backend/routes/api/instances.$name.start.ts +0 -18
- package/src/backend/routes/api/instances.$name.stop.ts +0 -23
- package/src/backend/routes/api/instances.$name.ts +0 -12
- package/src/backend/routes/api/instances.ts +0 -16
- package/src/backend/routes/api/knowledge.candidates.$candidateId.promote.ts +0 -32
- package/src/backend/routes/api/knowledge.candidates.$candidateId.ts +0 -50
- package/src/backend/routes/api/knowledge.candidates.ts +0 -10
- package/src/backend/routes/api/knowledge.project-context.ts +0 -29
- package/src/backend/routes/api/knowledge.search.ts +0 -62
- package/src/backend/routes/api/knowledge.sessions.$sessionId.candidates.ts +0 -26
- package/src/backend/routes/api/logs.$id.body.ts +0 -58
- package/src/backend/routes/api/logs.$id.chunks.ts +0 -37
- package/src/backend/routes/api/logs.$id.replay.ts +0 -297
- package/src/backend/routes/api/logs.$id.ts +0 -23
- package/src/backend/routes/api/logs.import.ts +0 -39
- package/src/backend/routes/api/logs.stream.ts +0 -174
- package/src/backend/routes/api/logs.ts +0 -214
- package/src/backend/routes/api/mcp.ts +0 -25
- package/src/backend/routes/api/models.ts +0 -10
- package/src/backend/routes/api/pi-agent.ts +0 -29
- package/src/backend/routes/api/providers.$providerId.model-metadata.ts +0 -173
- package/src/backend/routes/api/providers.$providerId.test.log.ts +0 -342
- package/src/backend/routes/api/providers.$providerId.ts +0 -111
- package/src/backend/routes/api/providers.export.ts +0 -44
- package/src/backend/routes/api/providers.import.ts +0 -81
- package/src/backend/routes/api/providers.scan.ts +0 -28
- package/src/backend/routes/api/providers.ts +0 -102
- package/src/backend/routes/api/runs.$runId.evidence.ts +0 -55
- package/src/backend/routes/api/runs.$runId.ts +0 -50
- package/src/backend/routes/api/runs.ts +0 -62
- package/src/backend/routes/api/runtime.ts +0 -46
- package/src/backend/routes/api/sessions.ts +0 -51
- package/src/backend/routes/api/storage.ts +0 -56
- package/src/backend/routes/livez.ts +0 -13
- package/src/backend/routes/metrics.ts +0 -14
- package/src/backend/routes/proxy/$.ts +0 -15
- package/src/backend/routes/readyz.ts +0 -18
- package/src/backend/start.ts +0 -10
- package/src/cli/alias.ts +0 -431
- package/src/cli/detect-tools.ts +0 -123
- package/src/cli/doctor.ts +0 -836
- package/src/cli/instance.ts +0 -1071
- package/src/cli/instanceApi.ts +0 -213
- package/src/cli/instanceArgs.ts +0 -301
- package/src/cli/instanceControl.ts +0 -191
- package/src/cli/instanceModel.ts +0 -276
- package/src/cli/instanceRegistry.ts +0 -731
- package/src/cli/networkHints.ts +0 -170
- package/src/cli/onboard.ts +0 -1668
- package/src/cli/onboardTarget.ts +0 -228
- package/src/cli/rustBackendPackage.ts +0 -458
- package/src/cli/startupOutput.ts +0 -16
- package/src/cli/templates/codex-skill-onboard.ts +0 -320
- package/src/cli/templates/command-onboard.ts +0 -25
- package/src/cli/templates/skill-onboard.ts +0 -625
- package/src/cli.ts +0 -1433
- package/src/components/OnboardingBanner.tsx +0 -115
- package/src/components/ProxyViewer.tsx +0 -2259
- package/src/components/ProxyViewerContainer.tsx +0 -1076
- package/src/components/alerts/AlertsDialog.tsx +0 -615
- package/src/components/clients/ClientLogo.tsx +0 -175
- package/src/components/ecosystem/AgentLabDialog.tsx +0 -947
- package/src/components/errors/SafeErrorBoundary.tsx +0 -201
- package/src/components/groups/GroupsDialog.tsx +0 -1304
- package/src/components/inspector-pet/InspectorPet.tsx +0 -398
- package/src/components/inspector-pet/InspectorPetCrab3D.tsx +0 -455
- package/src/components/inspector-pet/inspectorPetLogic.ts +0 -272
- package/src/components/pi-agent/PiAgentPanel.tsx +0 -446
- package/src/components/pi-agent/piAgentChatLogic.ts +0 -273
- package/src/components/providers/ImportWizardDialog.tsx +0 -281
- package/src/components/providers/ProviderCard.tsx +0 -347
- package/src/components/providers/ProviderForm.tsx +0 -1183
- package/src/components/providers/ProviderLogo.tsx +0 -122
- package/src/components/providers/ProviderTestResultsView.tsx +0 -734
- package/src/components/providers/ProvidersPanel.tsx +0 -714
- package/src/components/providers/SettingsDialog.tsx +0 -1042
- package/src/components/providers/providerFormCapabilities.ts +0 -36
- package/src/components/proxy-viewer/AgentTraceSummary.tsx +0 -902
- package/src/components/proxy-viewer/AnswerMarkdown.tsx +0 -51
- package/src/components/proxy-viewer/ApplicationBar.tsx +0 -123
- package/src/components/proxy-viewer/CompareDrawer.tsx +0 -984
- package/src/components/proxy-viewer/ConversationGroup.tsx +0 -208
- package/src/components/proxy-viewer/ConversationGroupList.tsx +0 -652
- package/src/components/proxy-viewer/ConversationHeader.tsx +0 -429
- package/src/components/proxy-viewer/LiveConnectionStatus.tsx +0 -186
- package/src/components/proxy-viewer/LogEntry.tsx +0 -1419
- package/src/components/proxy-viewer/LogEntryHeader.tsx +0 -596
- package/src/components/proxy-viewer/ProviderLogoStack.tsx +0 -57
- package/src/components/proxy-viewer/RawExportWarning.tsx +0 -77
- package/src/components/proxy-viewer/ReplayDialog.tsx +0 -636
- package/src/components/proxy-viewer/RequestToolsPanel.tsx +0 -299
- package/src/components/proxy-viewer/ResponseView.tsx +0 -202
- package/src/components/proxy-viewer/SessionLoadProgressBar.tsx +0 -61
- package/src/components/proxy-viewer/StreamingChunkSequence.tsx +0 -265
- package/src/components/proxy-viewer/ThreadConnector.tsx +0 -165
- package/src/components/proxy-viewer/ToolTraceEvents.tsx +0 -64
- package/src/components/proxy-viewer/TurnGroup.tsx +0 -383
- package/src/components/proxy-viewer/TurnGroupList.tsx +0 -156
- package/src/components/proxy-viewer/accessibility.ts +0 -8
- package/src/components/proxy-viewer/anatomy/RequestAnatomy.tsx +0 -887
- package/src/components/proxy-viewer/anatomy/SegmentBar.tsx +0 -222
- package/src/components/proxy-viewer/anatomy/contextIntelligence.ts +0 -737
- package/src/components/proxy-viewer/anatomy/sessionContextSummary.ts +0 -268
- package/src/components/proxy-viewer/anatomy/tokenEstimate.ts +0 -53
- package/src/components/proxy-viewer/anatomy/types.ts +0 -41
- package/src/components/proxy-viewer/anatomy/useAnatomyJump.ts +0 -114
- package/src/components/proxy-viewer/bodyHydration.ts +0 -123
- package/src/components/proxy-viewer/cacheTrend.ts +0 -50
- package/src/components/proxy-viewer/diff/DiffView.tsx +0 -321
- package/src/components/proxy-viewer/diff/computeDiff.ts +0 -178
- package/src/components/proxy-viewer/diff/index.ts +0 -3
- package/src/components/proxy-viewer/formats/anthropic/ContentBlocks.tsx +0 -194
- package/src/components/proxy-viewer/formats/anthropic/ResponseView.tsx +0 -81
- package/src/components/proxy-viewer/formats/anthropic/thinkingExtract.ts +0 -21
- package/src/components/proxy-viewer/formats/index.tsx +0 -47
- package/src/components/proxy-viewer/formats/openai/ResponseView.tsx +0 -442
- package/src/components/proxy-viewer/index.ts +0 -9
- package/src/components/proxy-viewer/lazy.ts +0 -41
- package/src/components/proxy-viewer/liveConnectionState.ts +0 -158
- package/src/components/proxy-viewer/log-formats/anthropic.ts +0 -191
- package/src/components/proxy-viewer/log-formats/index.ts +0 -23
- package/src/components/proxy-viewer/log-formats/openai.ts +0 -256
- package/src/components/proxy-viewer/log-formats/types.ts +0 -40
- package/src/components/proxy-viewer/log-formats/unknown.ts +0 -18
- package/src/components/proxy-viewer/logEntryVisibility.ts +0 -73
- package/src/components/proxy-viewer/logFocus.ts +0 -54
- package/src/components/proxy-viewer/proxyViewerContainerLogic.ts +0 -124
- package/src/components/proxy-viewer/proxyViewerLogic.ts +0 -488
- package/src/components/proxy-viewer/replayComparison.ts +0 -131
- package/src/components/proxy-viewer/requestDiff.ts +0 -277
- package/src/components/proxy-viewer/requestTools.ts +0 -220
- package/src/components/proxy-viewer/useCopyFeedback.ts +0 -38
- package/src/components/proxy-viewer/useKeyboardNavigation.ts +0 -232
- package/src/components/proxy-viewer/viewerState.ts +0 -176
- package/src/components/ui/badge.tsx +0 -47
- package/src/components/ui/button.tsx +0 -47
- package/src/components/ui/collapsible.tsx +0 -21
- package/src/components/ui/confirm-dialog.tsx +0 -51
- package/src/components/ui/crab-logo.tsx +0 -45
- package/src/components/ui/crab-variants.tsx +0 -467
- package/src/components/ui/dialog.tsx +0 -130
- package/src/components/ui/icon-trigger.ts +0 -2
- package/src/components/ui/json-viewer-bulk.ts +0 -132
- package/src/components/ui/json-viewer.tsx +0 -508
- package/src/components/ui/scroll-area.tsx +0 -54
- package/src/components/ui/select.tsx +0 -178
- package/src/components/ui/separator.tsx +0 -28
- package/src/components/ui/tabs.tsx +0 -88
- package/src/components/ui/tooltip.tsx +0 -51
- package/src/components/ui/transient-toast.tsx +0 -105
- package/src/contracts/anthropic.ts +0 -230
- package/src/contracts/index.ts +0 -59
- package/src/contracts/json.ts +0 -37
- package/src/contracts/log.ts +0 -139
- package/src/contracts/openai.ts +0 -267
- package/src/index.css +0 -11
- package/src/knowledge/candidateStore.ts +0 -94
- package/src/knowledge/distiller.ts +0 -98
- package/src/knowledge/openclawClient.ts +0 -161
- package/src/knowledge/openclawGatewayClient.ts +0 -249
- package/src/knowledge/openclawMarkdown.ts +0 -146
- package/src/knowledge/redactor.ts +0 -80
- package/src/knowledge/types.ts +0 -83
- package/src/lib/alertContract.ts +0 -76
- package/src/lib/apiClient.ts +0 -166
- package/src/lib/apiFormat.ts +0 -29
- package/src/lib/backendImplementation.ts +0 -16
- package/src/lib/basePath.ts +0 -107
- package/src/lib/browserRuntimeContract.ts +0 -124
- package/src/lib/browserRuntimeResolver.ts +0 -333
- package/src/lib/chunkLoadRecovery.ts +0 -83
- package/src/lib/claudeCodeStrip.ts +0 -98
- package/src/lib/clipboard.ts +0 -67
- package/src/lib/codingAgentEndpoints.ts +0 -54
- package/src/lib/ecosystemContract.ts +0 -130
- package/src/lib/export-logs.ts +0 -287
- package/src/lib/groupContract.ts +0 -166
- package/src/lib/instanceContract.ts +0 -239
- package/src/lib/jsonFile.ts +0 -46
- package/src/lib/logImportContract.ts +0 -12
- package/src/lib/managedInstance.ts +0 -112
- package/src/lib/mask.ts +0 -4
- package/src/lib/objectUtils.ts +0 -22
- package/src/lib/piAgentContract.ts +0 -102
- package/src/lib/providerContract.ts +0 -125
- package/src/lib/providerImportContract.ts +0 -27
- package/src/lib/providerModelMetadata.ts +0 -458
- package/src/lib/providerTestContract.ts +0 -170
- package/src/lib/providerTestPrompt.ts +0 -100
- package/src/lib/publicBasePathContext.ts +0 -137
- package/src/lib/resourceLimits.ts +0 -345
- package/src/lib/runContract.ts +0 -164
- package/src/lib/runtimeConfig.ts +0 -43
- package/src/lib/safeDiagnostic.ts +0 -38
- package/src/lib/safeFetch.ts +0 -508
- package/src/lib/serverPort.ts +0 -47
- package/src/lib/sessionInfoContract.ts +0 -78
- package/src/lib/sessionUrl.ts +0 -46
- package/src/lib/ssrfGuard.ts +0 -133
- package/src/lib/stopReason.ts +0 -130
- package/src/lib/themeMode.ts +0 -41
- package/src/lib/timeDisplay.ts +0 -22
- package/src/lib/toolTrace.ts +0 -290
- package/src/lib/uiScale.ts +0 -117
- package/src/lib/unknown.ts +0 -27
- package/src/lib/upstreamUrl.ts +0 -150
- package/src/lib/useAlerts.ts +0 -82
- package/src/lib/useGroupEvidence.ts +0 -37
- package/src/lib/useGroups.ts +0 -32
- package/src/lib/useOnboarding.ts +0 -93
- package/src/lib/useProviders.ts +0 -30
- package/src/lib/useStripConfig.ts +0 -154
- package/src/lib/useThemeMode.ts +0 -40
- package/src/lib/useUiScale.ts +0 -52
- package/src/lib/utils.ts +0 -78
- package/src/mcp/currentContext.ts +0 -65
- package/src/mcp/instanceHandlers.ts +0 -151
- package/src/mcp/loopback.ts +0 -88
- package/src/mcp/mode.ts +0 -75
- package/src/mcp/previewExtractor.ts +0 -233
- package/src/mcp/server.ts +0 -2274
- package/src/mcp/toolHandlers.ts +0 -1533
- package/src/proxy/alerts.ts +0 -664
- package/src/proxy/chunkStorage.ts +0 -123
- package/src/proxy/config.ts +0 -218
- package/src/proxy/constants.ts +0 -66
- package/src/proxy/dataDir.ts +0 -147
- package/src/proxy/ecosystemExecutionConfirmation.ts +0 -114
- package/src/proxy/ecosystemExecutionRoute.ts +0 -116
- package/src/proxy/ecosystemRegistry.ts +0 -296
- package/src/proxy/ecosystemTasks.ts +0 -415
- package/src/proxy/evidenceAnalysis.ts +0 -526
- package/src/proxy/evidenceExporter.ts +0 -235
- package/src/proxy/formats/anthropic/anthropicProvider.ts +0 -75
- package/src/proxy/formats/anthropic/handler.ts +0 -75
- package/src/proxy/formats/anthropic/index.ts +0 -13
- package/src/proxy/formats/anthropic/register.ts +0 -4
- package/src/proxy/formats/anthropic/schemas.ts +0 -6
- package/src/proxy/formats/anthropic/stream.ts +0 -205
- package/src/proxy/formats/handler.ts +0 -46
- package/src/proxy/formats/index.ts +0 -13
- package/src/proxy/formats/jsonSchema.ts +0 -2
- package/src/proxy/formats/openai/alibabaProvider.ts +0 -34
- package/src/proxy/formats/openai/codexMetadata.ts +0 -61
- package/src/proxy/formats/openai/handler.ts +0 -133
- package/src/proxy/formats/openai/index.ts +0 -33
- package/src/proxy/formats/openai/provider.ts +0 -50
- package/src/proxy/formats/openai/register.ts +0 -4
- package/src/proxy/formats/openai/schemas.ts +0 -25
- package/src/proxy/formats/openai/stream.ts +0 -600
- package/src/proxy/formats/openai/zhipuProvider.ts +0 -31
- package/src/proxy/formats/providerAdapter.ts +0 -50
- package/src/proxy/formats/providerRegistry.ts +0 -51
- package/src/proxy/formats/providers/index.ts +0 -3
- package/src/proxy/formats/registry.ts +0 -65
- package/src/proxy/groupEvidenceExporter.ts +0 -371
- package/src/proxy/groupStore.ts +0 -336
- package/src/proxy/handler.ts +0 -729
- package/src/proxy/identityProxy.ts +0 -1842
- package/src/proxy/jsonlRecovery.ts +0 -554
- package/src/proxy/logBodyChunks.ts +0 -91
- package/src/proxy/logFinalizer.ts +0 -777
- package/src/proxy/logFinalizer.worker.ts +0 -24
- package/src/proxy/logImportUpload.ts +0 -128
- package/src/proxy/logImporter.ts +0 -813
- package/src/proxy/logIndex.ts +0 -663
- package/src/proxy/logSearch.ts +0 -122
- package/src/proxy/logger.ts +0 -537
- package/src/proxy/openaiOrphanToolStrip.ts +0 -142
- package/src/proxy/platformCommands.ts +0 -258
- package/src/proxy/privateDataPath.ts +0 -419
- package/src/proxy/providerImporters.ts +0 -578
- package/src/proxy/providerScanStore.ts +0 -87
- package/src/proxy/providerSecretStore.ts +0 -216
- package/src/proxy/providers.ts +0 -998
- package/src/proxy/rawStreamCapture.ts +0 -342
- package/src/proxy/runFailures.ts +0 -94
- package/src/proxy/runStore.ts +0 -214
- package/src/proxy/runtimeAdmission.ts +0 -55
- package/src/proxy/runtimeHealth.ts +0 -221
- package/src/proxy/runtimeMetrics.ts +0 -149
- package/src/proxy/runtimeShutdown.ts +0 -157
- package/src/proxy/schemas.ts +0 -112
- package/src/proxy/sessionArchive.ts +0 -479
- package/src/proxy/sessionInfo.ts +0 -266
- package/src/proxy/sessionProcess.ts +0 -194
- package/src/proxy/sessionRuntime.ts +0 -121
- package/src/proxy/sessionSupervisor.ts +0 -305
- package/src/proxy/sessionWorkerEntry.ts +0 -26
- package/src/proxy/shutdownCoordinator.ts +0 -90
- package/src/proxy/socketTracker.ts +0 -639
- package/src/proxy/sqliteLogIndex.ts +0 -733
- package/src/proxy/storageLifecycle.ts +0 -432
- package/src/proxy/store.ts +0 -1773
- package/src/proxy/streamTiming.ts +0 -31
- package/src/proxy/toolSchemaWarnings.ts +0 -529
- package/src/proxy/uiAssetServer.ts +0 -106
- package/src/proxy/upstream.ts +0 -127
- package/src/services/alerts.ts +0 -12
- package/src/services/groups.ts +0 -119
- package/src/services/piAgent.ts +0 -421
- package/src/services/piAgentRetrieval.ts +0 -1180
- package/src/services/result.ts +0 -17
- package/src/services/runs.ts +0 -76
- package/src/ui/bootstrap.ts +0 -167
- package/src/ui/index.html +0 -38
- package/src/ui/logsStreamClient.ts +0 -20
- package/src/ui/main.tsx +0 -13
- package/src/ui/public/runtime-config.js +0 -2
- package/src/ui/router.tsx +0 -13
- package/src/ui/routes/__root.tsx +0 -69
- package/src/ui/routes/index.tsx +0 -35
- package/src/ui/routes/session/$sessionId.tsx +0 -50
- package/src/ui/runtimeDiscovery.ts +0 -50
|
@@ -1,714 +0,0 @@
|
|
|
1
|
-
import { type JSX, useState, useEffect, useCallback, useMemo, useRef } from "react";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
import { Button } from "../ui/button";
|
|
4
|
-
import { Plus, AlertCircle, Copy, Check, Download, Upload, Scan } from "lucide-react";
|
|
5
|
-
import { ImportWizardDialog } from "./ImportWizardDialog";
|
|
6
|
-
import { ConfirmDialog } from "../ui/confirm-dialog";
|
|
7
|
-
import { ProviderCard } from "./ProviderCard";
|
|
8
|
-
import { ProviderForm } from "./ProviderForm";
|
|
9
|
-
import {
|
|
10
|
-
ApiTimeoutError,
|
|
11
|
-
fetchJsonWithTimeout,
|
|
12
|
-
fetchWithTimeout,
|
|
13
|
-
parseJsonResponse,
|
|
14
|
-
readApiError,
|
|
15
|
-
} from "../../lib/apiClient";
|
|
16
|
-
import { copyTextToClipboard } from "../../lib/clipboard";
|
|
17
|
-
import {
|
|
18
|
-
RedactedProviderDtoSchema,
|
|
19
|
-
type ProviderConfig,
|
|
20
|
-
type ProviderModelMetadata,
|
|
21
|
-
} from "../../lib/providerContract";
|
|
22
|
-
import {
|
|
23
|
-
createFailedProviderTestResults,
|
|
24
|
-
createPendingProviderTestResults,
|
|
25
|
-
ProviderTestResultsSchema,
|
|
26
|
-
type ProviderTestResults as TestResults,
|
|
27
|
-
} from "../../lib/providerTestContract";
|
|
28
|
-
import { useStripConfig } from "../../lib/useStripConfig";
|
|
29
|
-
|
|
30
|
-
export type { ProviderTestResults as TestResults } from "../../lib/providerTestContract";
|
|
31
|
-
|
|
32
|
-
const ConfigPathsResponseSchema = z.object({
|
|
33
|
-
providerConfig: z.string(),
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
const ImportResponseSchema = z.object({
|
|
37
|
-
success: z.boolean().optional(),
|
|
38
|
-
imported: z.number().optional(),
|
|
39
|
-
message: z.string().optional(),
|
|
40
|
-
errors: z.array(z.string()).optional(),
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
const ModelMetadataRefreshResponseSchema = z.object({
|
|
44
|
-
provider: RedactedProviderDtoSchema,
|
|
45
|
-
imported: z.number(),
|
|
46
|
-
matchedModels: z.array(z.string()),
|
|
47
|
-
missingModels: z.array(z.string()),
|
|
48
|
-
sourceUrl: z.string(),
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
const NETWORK_ERROR_MESSAGE = "Network error: could not reach the server. Is the proxy running?";
|
|
52
|
-
const CONFIG_PATH_FETCH_TIMEOUT_MS = 5_000;
|
|
53
|
-
const PROVIDER_TEST_LOG_TIMEOUT_MS = 5_000;
|
|
54
|
-
const PROVIDER_WRITE_TIMEOUT_MS = 15_000;
|
|
55
|
-
const PROVIDER_DELETE_TIMEOUT_MS = 10_000;
|
|
56
|
-
const PROVIDER_EXPORT_TIMEOUT_MS = 20_000;
|
|
57
|
-
const PROVIDER_IMPORT_TIMEOUT_MS = 20_000;
|
|
58
|
-
const PROVIDER_METADATA_TIMEOUT_MS = 30_000;
|
|
59
|
-
|
|
60
|
-
type ProviderFormData = {
|
|
61
|
-
name: string;
|
|
62
|
-
apiKey: string;
|
|
63
|
-
models: string[];
|
|
64
|
-
anthropicBaseUrl?: string;
|
|
65
|
-
openaiBaseUrl?: string;
|
|
66
|
-
openaiResponsesBaseUrl?: string;
|
|
67
|
-
apiDocsUrl?: string;
|
|
68
|
-
modelMetadataUrl?: string;
|
|
69
|
-
modelMetadata?: ProviderModelMetadata[];
|
|
70
|
-
source?: "company" | "personal";
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
function endpointPayloadValue(
|
|
74
|
-
value: string | undefined,
|
|
75
|
-
preserveEmptyEndpoints: boolean,
|
|
76
|
-
): string | undefined {
|
|
77
|
-
if ((value?.length ?? 0) > 0) return value;
|
|
78
|
-
return preserveEmptyEndpoints && value !== undefined ? "" : undefined;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function createProviderPayload(data: ProviderFormData, preserveEmptyEndpoints = false) {
|
|
82
|
-
return {
|
|
83
|
-
name: data.name,
|
|
84
|
-
...(data.apiKey.trim() === "" ? {} : { apiKey: data.apiKey }),
|
|
85
|
-
models: data.models,
|
|
86
|
-
anthropicBaseUrl: endpointPayloadValue(data.anthropicBaseUrl, preserveEmptyEndpoints),
|
|
87
|
-
openaiBaseUrl: endpointPayloadValue(data.openaiBaseUrl, preserveEmptyEndpoints),
|
|
88
|
-
openaiResponsesBaseUrl: endpointPayloadValue(
|
|
89
|
-
data.openaiResponsesBaseUrl,
|
|
90
|
-
preserveEmptyEndpoints,
|
|
91
|
-
),
|
|
92
|
-
apiDocsUrl: (data.apiDocsUrl?.length ?? 0) > 0 ? data.apiDocsUrl : undefined,
|
|
93
|
-
modelMetadataUrl: (data.modelMetadataUrl?.length ?? 0) > 0 ? data.modelMetadataUrl : undefined,
|
|
94
|
-
modelMetadata: data.modelMetadata,
|
|
95
|
-
source: data.source,
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function getProviderTestTimeoutSeconds(
|
|
100
|
-
provider: ProviderConfig | undefined,
|
|
101
|
-
timeoutSecondsPerModel: number,
|
|
102
|
-
): number {
|
|
103
|
-
const modelCount =
|
|
104
|
-
provider?.models?.map((model) => model.trim()).filter((model) => model !== "").length ?? 0;
|
|
105
|
-
return Math.max(1, modelCount) * timeoutSecondsPerModel;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
async function persistProviderTestLog(providerId: string, results: TestResults): Promise<void> {
|
|
109
|
-
if (results.models === undefined) {
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
try {
|
|
113
|
-
await fetchWithTimeout(`/api/providers/${providerId}/test/log`, PROVIDER_TEST_LOG_TIMEOUT_MS, {
|
|
114
|
-
method: "POST",
|
|
115
|
-
headers: { "Content-Type": "application/json" },
|
|
116
|
-
body: JSON.stringify(results),
|
|
117
|
-
});
|
|
118
|
-
} catch {
|
|
119
|
-
// Provider connection status is primary; log persistence is best-effort.
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
type ProvidersPanelProps = {
|
|
124
|
-
externalProviders?: ProviderConfig[];
|
|
125
|
-
isLoading?: boolean;
|
|
126
|
-
externalTestResults?: Record<string, TestResults>;
|
|
127
|
-
externalTestingProviders?: Set<string>;
|
|
128
|
-
externalTestingTimeLeft?: Record<string, number>;
|
|
129
|
-
onProvidersMutate?: () => Promise<unknown>;
|
|
130
|
-
onTestResultsChange?: (providerId: string, results: TestResults) => void;
|
|
131
|
-
onTestingProvidersChange?: (providerId: string, isTesting: boolean) => void;
|
|
132
|
-
onTestingTimeLeftChange?: (providerId: string, seconds: number | undefined) => void;
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
export function ProvidersPanel({
|
|
136
|
-
externalProviders,
|
|
137
|
-
isLoading = false,
|
|
138
|
-
externalTestResults,
|
|
139
|
-
externalTestingProviders,
|
|
140
|
-
externalTestingTimeLeft,
|
|
141
|
-
onProvidersMutate,
|
|
142
|
-
onTestResultsChange,
|
|
143
|
-
onTestingProvidersChange,
|
|
144
|
-
onTestingTimeLeftChange,
|
|
145
|
-
}: ProvidersPanelProps): JSX.Element {
|
|
146
|
-
const [showForm, setShowForm] = useState(false);
|
|
147
|
-
const [editingProvider, setEditingProvider] = useState<ProviderConfig | undefined>();
|
|
148
|
-
const [error, setError] = useState<string | null>(null);
|
|
149
|
-
const [internalTestResults, setInternalTestResults] = useState<Record<string, TestResults>>({});
|
|
150
|
-
const [internalTestingProviders, setInternalTestingProviders] = useState<Set<string>>(new Set());
|
|
151
|
-
const [internalTestingTimeLeft, setInternalTestingTimeLeft] = useState<Record<string, number>>(
|
|
152
|
-
{},
|
|
153
|
-
);
|
|
154
|
-
const [configPath, setConfigPath] = useState<string | null>(null);
|
|
155
|
-
const [configPathCopied, setConfigPathCopied] = useState(false);
|
|
156
|
-
const [highlightedProviderId, setHighlightedProviderId] = useState<string | null>(null);
|
|
157
|
-
const [showImportWizard, setShowImportWizard] = useState(false);
|
|
158
|
-
const [confirmOpen, setConfirmOpen] = useState(false);
|
|
159
|
-
const [deletingProviderId, setDeletingProviderId] = useState<string | null>(null);
|
|
160
|
-
const [sourceFilter, setSourceFilter] = useState<"all" | "personal" | "company">("all");
|
|
161
|
-
const [refreshingMetadataProviders, setRefreshingMetadataProviders] = useState<Set<string>>(
|
|
162
|
-
new Set(),
|
|
163
|
-
);
|
|
164
|
-
const { providerTestTimeoutSeconds } = useStripConfig();
|
|
165
|
-
const listScrollRef = useRef<HTMLDivElement>(null);
|
|
166
|
-
const highlightTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
167
|
-
|
|
168
|
-
// Use external state if provided (from SWR), otherwise use internal state
|
|
169
|
-
const providers = externalProviders ?? [];
|
|
170
|
-
const filteredProviders = useMemo(() => {
|
|
171
|
-
const filtered =
|
|
172
|
-
sourceFilter === "all" ? providers : providers.filter((p) => p.source === sourceFilter);
|
|
173
|
-
if (sourceFilter === "all") {
|
|
174
|
-
return [...filtered].sort((a, b) => {
|
|
175
|
-
const order: Record<string, number> = { personal: 0, company: 1 };
|
|
176
|
-
return (order[a.source ?? ""] ?? 2) - (order[b.source ?? ""] ?? 2);
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
return filtered;
|
|
180
|
-
}, [providers, sourceFilter]);
|
|
181
|
-
const testResults = externalTestResults ?? internalTestResults;
|
|
182
|
-
const testingProviders = externalTestingProviders ?? internalTestingProviders;
|
|
183
|
-
const testingTimeLeft = externalTestingTimeLeft ?? internalTestingTimeLeft;
|
|
184
|
-
const setTestingTimeLeft = onTestingTimeLeftChange
|
|
185
|
-
? (id: string, seconds: number | undefined) => onTestingTimeLeftChange(id, seconds)
|
|
186
|
-
: (id: string, seconds: number | undefined) => {
|
|
187
|
-
if (seconds === undefined) {
|
|
188
|
-
setInternalTestingTimeLeft((prev) => {
|
|
189
|
-
const next = { ...prev };
|
|
190
|
-
delete next[id];
|
|
191
|
-
return next;
|
|
192
|
-
});
|
|
193
|
-
} else {
|
|
194
|
-
setInternalTestingTimeLeft((prev) => ({ ...prev, [id]: seconds }));
|
|
195
|
-
}
|
|
196
|
-
};
|
|
197
|
-
|
|
198
|
-
useEffect(() => {
|
|
199
|
-
void (async () => {
|
|
200
|
-
try {
|
|
201
|
-
const data = await fetchJsonWithTimeout(
|
|
202
|
-
"/api/config/paths",
|
|
203
|
-
ConfigPathsResponseSchema,
|
|
204
|
-
CONFIG_PATH_FETCH_TIMEOUT_MS,
|
|
205
|
-
);
|
|
206
|
-
setConfigPath(data.providerConfig);
|
|
207
|
-
} catch {
|
|
208
|
-
// Ignore
|
|
209
|
-
}
|
|
210
|
-
})();
|
|
211
|
-
}, []);
|
|
212
|
-
|
|
213
|
-
const triggerHighlight = useCallback((providerId: string) => {
|
|
214
|
-
// Cancel any existing highlight timeout
|
|
215
|
-
if (highlightTimeoutRef.current !== null) {
|
|
216
|
-
clearTimeout(highlightTimeoutRef.current);
|
|
217
|
-
}
|
|
218
|
-
setHighlightedProviderId(providerId);
|
|
219
|
-
// Scroll the list to bring the card into view
|
|
220
|
-
listScrollRef.current?.scrollTo({
|
|
221
|
-
top: listScrollRef.current.scrollHeight,
|
|
222
|
-
behavior: "smooth",
|
|
223
|
-
});
|
|
224
|
-
// Clear highlight after 2 seconds
|
|
225
|
-
highlightTimeoutRef.current = setTimeout(() => {
|
|
226
|
-
setHighlightedProviderId(null);
|
|
227
|
-
highlightTimeoutRef.current = null;
|
|
228
|
-
}, 2000);
|
|
229
|
-
}, []);
|
|
230
|
-
|
|
231
|
-
useEffect(
|
|
232
|
-
() => () => {
|
|
233
|
-
if (highlightTimeoutRef.current !== null) {
|
|
234
|
-
clearTimeout(highlightTimeoutRef.current);
|
|
235
|
-
}
|
|
236
|
-
},
|
|
237
|
-
[],
|
|
238
|
-
);
|
|
239
|
-
|
|
240
|
-
const refreshProviders = useCallback((): void => {
|
|
241
|
-
onProvidersMutate?.().catch(() => {});
|
|
242
|
-
}, [onProvidersMutate]);
|
|
243
|
-
|
|
244
|
-
const updateTestResults = useCallback(
|
|
245
|
-
(providerId: string, results: TestResults): void => {
|
|
246
|
-
if (onTestResultsChange) {
|
|
247
|
-
onTestResultsChange(providerId, results);
|
|
248
|
-
} else {
|
|
249
|
-
setInternalTestResults((prev) => ({ ...prev, [providerId]: results }));
|
|
250
|
-
}
|
|
251
|
-
},
|
|
252
|
-
[onTestResultsChange],
|
|
253
|
-
);
|
|
254
|
-
|
|
255
|
-
const updateTestingState = useCallback(
|
|
256
|
-
(providerId: string, isTesting: boolean): void => {
|
|
257
|
-
if (onTestingProvidersChange) {
|
|
258
|
-
onTestingProvidersChange(providerId, isTesting);
|
|
259
|
-
return;
|
|
260
|
-
}
|
|
261
|
-
setInternalTestingProviders((prev) => {
|
|
262
|
-
const next = new Set(prev);
|
|
263
|
-
if (isTesting) next.add(providerId);
|
|
264
|
-
else next.delete(providerId);
|
|
265
|
-
return next;
|
|
266
|
-
});
|
|
267
|
-
},
|
|
268
|
-
[onTestingProvidersChange],
|
|
269
|
-
);
|
|
270
|
-
|
|
271
|
-
const runTest = useCallback(
|
|
272
|
-
async (providerId: string): Promise<void> => {
|
|
273
|
-
// Clear previous test results when starting a new test
|
|
274
|
-
updateTestResults(providerId, createPendingProviderTestResults());
|
|
275
|
-
updateTestingState(providerId, true);
|
|
276
|
-
|
|
277
|
-
// Create abort controller for this test request
|
|
278
|
-
const controller = new AbortController();
|
|
279
|
-
const provider = providers.find((candidate) => candidate.id === providerId);
|
|
280
|
-
const timeoutSeconds = getProviderTestTimeoutSeconds(provider, providerTestTimeoutSeconds);
|
|
281
|
-
|
|
282
|
-
// Start countdown
|
|
283
|
-
let remaining = timeoutSeconds;
|
|
284
|
-
setTestingTimeLeft(providerId, remaining);
|
|
285
|
-
const intervalId = setInterval(() => {
|
|
286
|
-
remaining--;
|
|
287
|
-
setTestingTimeLeft(providerId, remaining);
|
|
288
|
-
if (remaining <= 0) {
|
|
289
|
-
clearInterval(intervalId);
|
|
290
|
-
// Abort the fetch request when time runs out
|
|
291
|
-
controller.abort();
|
|
292
|
-
}
|
|
293
|
-
}, 1000);
|
|
294
|
-
|
|
295
|
-
try {
|
|
296
|
-
const results = await fetchJsonWithTimeout(
|
|
297
|
-
`/api/providers/${providerId}/test`,
|
|
298
|
-
ProviderTestResultsSchema,
|
|
299
|
-
timeoutSeconds * 1000 + 1000,
|
|
300
|
-
{
|
|
301
|
-
method: "POST",
|
|
302
|
-
signal: controller.signal,
|
|
303
|
-
},
|
|
304
|
-
(response) => `HTTP ${response.status}: ${response.statusText}`,
|
|
305
|
-
);
|
|
306
|
-
updateTestResults(providerId, results);
|
|
307
|
-
await persistProviderTestLog(providerId, results);
|
|
308
|
-
} catch (err) {
|
|
309
|
-
// Check if this was an abort (timeout)
|
|
310
|
-
const isAbort = err instanceof Error && err.name === "AbortError";
|
|
311
|
-
const isTimeout = err instanceof ApiTimeoutError;
|
|
312
|
-
if (isAbort || isTimeout) {
|
|
313
|
-
updateTestResults(
|
|
314
|
-
providerId,
|
|
315
|
-
createFailedProviderTestResults("Request timed out", "timeout"),
|
|
316
|
-
);
|
|
317
|
-
} else if (err instanceof Error) {
|
|
318
|
-
updateTestResults(
|
|
319
|
-
providerId,
|
|
320
|
-
createFailedProviderTestResults(err.message, "server_error"),
|
|
321
|
-
);
|
|
322
|
-
}
|
|
323
|
-
} finally {
|
|
324
|
-
// Always clear the countdown and testing state, even if an error occurs
|
|
325
|
-
clearInterval(intervalId);
|
|
326
|
-
setTestingTimeLeft(providerId, undefined);
|
|
327
|
-
updateTestingState(providerId, false);
|
|
328
|
-
}
|
|
329
|
-
},
|
|
330
|
-
[
|
|
331
|
-
providerTestTimeoutSeconds,
|
|
332
|
-
providers,
|
|
333
|
-
setTestingTimeLeft,
|
|
334
|
-
updateTestResults,
|
|
335
|
-
updateTestingState,
|
|
336
|
-
],
|
|
337
|
-
);
|
|
338
|
-
|
|
339
|
-
const refreshProviderMetadata = useCallback(
|
|
340
|
-
async (providerId: string, url?: string, showError = true): Promise<boolean> => {
|
|
341
|
-
setRefreshingMetadataProviders((prev) => {
|
|
342
|
-
const next = new Set(prev);
|
|
343
|
-
next.add(providerId);
|
|
344
|
-
return next;
|
|
345
|
-
});
|
|
346
|
-
try {
|
|
347
|
-
const payload = url !== undefined && url.trim() !== "" ? { url } : {};
|
|
348
|
-
const data = await fetchJsonWithTimeout(
|
|
349
|
-
`/api/providers/${providerId}/model-metadata`,
|
|
350
|
-
ModelMetadataRefreshResponseSchema,
|
|
351
|
-
PROVIDER_METADATA_TIMEOUT_MS,
|
|
352
|
-
{
|
|
353
|
-
method: "POST",
|
|
354
|
-
headers: { "Content-Type": "application/json" },
|
|
355
|
-
body: JSON.stringify(payload),
|
|
356
|
-
},
|
|
357
|
-
() => "Failed to refresh model metadata",
|
|
358
|
-
);
|
|
359
|
-
if (data.imported === 0 && showError) {
|
|
360
|
-
setError("No matching model metadata found for this provider.");
|
|
361
|
-
} else {
|
|
362
|
-
setError(null);
|
|
363
|
-
}
|
|
364
|
-
triggerHighlight(data.provider.id);
|
|
365
|
-
refreshProviders();
|
|
366
|
-
return data.imported > 0;
|
|
367
|
-
} catch (err) {
|
|
368
|
-
if (showError) {
|
|
369
|
-
setError(err instanceof Error ? err.message : NETWORK_ERROR_MESSAGE);
|
|
370
|
-
}
|
|
371
|
-
return false;
|
|
372
|
-
} finally {
|
|
373
|
-
setRefreshingMetadataProviders((prev) => {
|
|
374
|
-
const next = new Set(prev);
|
|
375
|
-
next.delete(providerId);
|
|
376
|
-
return next;
|
|
377
|
-
});
|
|
378
|
-
}
|
|
379
|
-
},
|
|
380
|
-
[refreshProviders, triggerHighlight],
|
|
381
|
-
);
|
|
382
|
-
|
|
383
|
-
function handleAddProvider(data: ProviderFormData): void {
|
|
384
|
-
void (async () => {
|
|
385
|
-
try {
|
|
386
|
-
const newProvider = await fetchJsonWithTimeout(
|
|
387
|
-
"/api/providers",
|
|
388
|
-
RedactedProviderDtoSchema,
|
|
389
|
-
PROVIDER_WRITE_TIMEOUT_MS,
|
|
390
|
-
{
|
|
391
|
-
method: "POST",
|
|
392
|
-
headers: { "Content-Type": "application/json" },
|
|
393
|
-
body: JSON.stringify(createProviderPayload(data)),
|
|
394
|
-
},
|
|
395
|
-
() => "Failed to add provider",
|
|
396
|
-
);
|
|
397
|
-
setShowForm(false);
|
|
398
|
-
triggerHighlight(newProvider.id);
|
|
399
|
-
if (data.modelMetadataUrl !== undefined && data.modelMetadataUrl.trim() !== "") {
|
|
400
|
-
await refreshProviderMetadata(newProvider.id, data.modelMetadataUrl, false);
|
|
401
|
-
}
|
|
402
|
-
refreshProviders();
|
|
403
|
-
await runTest(newProvider.id);
|
|
404
|
-
} catch (err) {
|
|
405
|
-
setError(err instanceof Error ? err.message : NETWORK_ERROR_MESSAGE);
|
|
406
|
-
}
|
|
407
|
-
})();
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
function handleUpdateProvider(data: ProviderFormData): void {
|
|
411
|
-
if (!editingProvider) return;
|
|
412
|
-
void (async () => {
|
|
413
|
-
try {
|
|
414
|
-
const updated = await fetchJsonWithTimeout(
|
|
415
|
-
`/api/providers/${editingProvider.id}`,
|
|
416
|
-
RedactedProviderDtoSchema,
|
|
417
|
-
PROVIDER_WRITE_TIMEOUT_MS,
|
|
418
|
-
{
|
|
419
|
-
method: "PUT",
|
|
420
|
-
headers: { "Content-Type": "application/json" },
|
|
421
|
-
body: JSON.stringify(createProviderPayload(data, true)),
|
|
422
|
-
},
|
|
423
|
-
() => "Failed to update provider",
|
|
424
|
-
);
|
|
425
|
-
setEditingProvider(undefined);
|
|
426
|
-
triggerHighlight(updated.id);
|
|
427
|
-
if (data.modelMetadataUrl !== undefined && data.modelMetadataUrl.trim() !== "") {
|
|
428
|
-
await refreshProviderMetadata(updated.id, data.modelMetadataUrl, false);
|
|
429
|
-
}
|
|
430
|
-
refreshProviders();
|
|
431
|
-
// Only run connection test when critical fields (apiKey, model, base URLs) changed
|
|
432
|
-
const criticalFieldsChanged =
|
|
433
|
-
data.apiKey.trim() !== "" ||
|
|
434
|
-
JSON.stringify(data.models) !== JSON.stringify(editingProvider.models) ||
|
|
435
|
-
(data.anthropicBaseUrl ?? "") !== (editingProvider.anthropicBaseUrl ?? "") ||
|
|
436
|
-
(data.openaiBaseUrl ?? "") !== (editingProvider.openaiBaseUrl ?? "") ||
|
|
437
|
-
(data.openaiResponsesBaseUrl ?? "") !== (editingProvider.openaiResponsesBaseUrl ?? "");
|
|
438
|
-
if (criticalFieldsChanged) {
|
|
439
|
-
await runTest(updated.id);
|
|
440
|
-
}
|
|
441
|
-
} catch (err) {
|
|
442
|
-
setError(err instanceof Error ? err.message : NETWORK_ERROR_MESSAGE);
|
|
443
|
-
}
|
|
444
|
-
})();
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
function handleDeleteProvider(providerId: string): void {
|
|
448
|
-
setDeletingProviderId(providerId);
|
|
449
|
-
setConfirmOpen(true);
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
function executeDelete(): void {
|
|
453
|
-
const providerId = deletingProviderId;
|
|
454
|
-
if (providerId === null) return;
|
|
455
|
-
void (async () => {
|
|
456
|
-
let res: Response;
|
|
457
|
-
try {
|
|
458
|
-
res = await fetchWithTimeout(`/api/providers/${providerId}`, PROVIDER_DELETE_TIMEOUT_MS, {
|
|
459
|
-
method: "DELETE",
|
|
460
|
-
});
|
|
461
|
-
} catch {
|
|
462
|
-
setError(NETWORK_ERROR_MESSAGE);
|
|
463
|
-
return;
|
|
464
|
-
}
|
|
465
|
-
if (!res.ok) {
|
|
466
|
-
setError(await readApiError(res, "Failed to delete provider"));
|
|
467
|
-
return;
|
|
468
|
-
}
|
|
469
|
-
refreshProviders();
|
|
470
|
-
})();
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
const fileInputRef = useRef<HTMLInputElement>(null);
|
|
474
|
-
|
|
475
|
-
function handleExport(includeKeys: boolean): void {
|
|
476
|
-
const url = `/api/providers/export${includeKeys ? "?includeKeys=true" : ""}`;
|
|
477
|
-
void (async () => {
|
|
478
|
-
try {
|
|
479
|
-
const res = await fetchWithTimeout(url, PROVIDER_EXPORT_TIMEOUT_MS);
|
|
480
|
-
if (!res.ok) {
|
|
481
|
-
setError("Failed to export providers");
|
|
482
|
-
return;
|
|
483
|
-
}
|
|
484
|
-
const blob = await res.blob();
|
|
485
|
-
const downloadUrl = URL.createObjectURL(blob);
|
|
486
|
-
const a = document.createElement("a");
|
|
487
|
-
a.href = downloadUrl;
|
|
488
|
-
a.download =
|
|
489
|
-
res.headers.get("Content-Disposition")?.match(/filename="(.+)"/)?.[1] ?? "providers.json";
|
|
490
|
-
document.body.appendChild(a);
|
|
491
|
-
a.click();
|
|
492
|
-
document.body.removeChild(a);
|
|
493
|
-
URL.revokeObjectURL(downloadUrl);
|
|
494
|
-
} catch {
|
|
495
|
-
setError("Failed to export providers");
|
|
496
|
-
}
|
|
497
|
-
})();
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
function handleImportClick(): void {
|
|
501
|
-
fileInputRef.current?.click();
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
function handleFileChange(e: React.ChangeEvent<HTMLInputElement>): void {
|
|
505
|
-
const file = e.target.files?.[0];
|
|
506
|
-
if (!file) return;
|
|
507
|
-
|
|
508
|
-
void (async () => {
|
|
509
|
-
try {
|
|
510
|
-
const text = await file.text();
|
|
511
|
-
const res = await fetchWithTimeout("/api/providers/import", PROVIDER_IMPORT_TIMEOUT_MS, {
|
|
512
|
-
method: "POST",
|
|
513
|
-
headers: { "Content-Type": "application/json" },
|
|
514
|
-
body: JSON.stringify(text),
|
|
515
|
-
});
|
|
516
|
-
const data = await parseJsonResponse(res, ImportResponseSchema);
|
|
517
|
-
if (res.ok && data.imported !== undefined && data.imported > 0) {
|
|
518
|
-
refreshProviders();
|
|
519
|
-
// Show success message via error state temporarily
|
|
520
|
-
setError(null);
|
|
521
|
-
// Use a ref or state to show success - for now just refresh list
|
|
522
|
-
} else if (data.errors && data.errors.length > 0) {
|
|
523
|
-
setError(data.errors.join("; "));
|
|
524
|
-
} else {
|
|
525
|
-
setError(data.message ?? "Import failed");
|
|
526
|
-
}
|
|
527
|
-
} catch {
|
|
528
|
-
setError("Failed to import providers");
|
|
529
|
-
}
|
|
530
|
-
// Reset file input
|
|
531
|
-
e.target.value = "";
|
|
532
|
-
})();
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
// Only show loading if we are actually loading (prevents flashing when reopening Settings during test)
|
|
536
|
-
if (isLoading) {
|
|
537
|
-
return (
|
|
538
|
-
<div className="flex items-center justify-center py-8">
|
|
539
|
-
<p className="text-sm text-muted-foreground">Loading providers...</p>
|
|
540
|
-
</div>
|
|
541
|
-
);
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
if (showForm || editingProvider) {
|
|
545
|
-
return (
|
|
546
|
-
<div className="space-y-4">
|
|
547
|
-
<div className="sticky top-0 z-10 flex items-center justify-between gap-3 rounded-[8px] bg-background/95 px-1 py-1 backdrop-blur">
|
|
548
|
-
<h3 className="text-lg font-medium">
|
|
549
|
-
{editingProvider ? "Edit Provider" : "Add New Provider"}
|
|
550
|
-
</h3>
|
|
551
|
-
</div>
|
|
552
|
-
<ProviderForm
|
|
553
|
-
provider={editingProvider}
|
|
554
|
-
onSubmit={editingProvider ? handleUpdateProvider : handleAddProvider}
|
|
555
|
-
onCancel={() => {
|
|
556
|
-
setShowForm(false);
|
|
557
|
-
setEditingProvider(undefined);
|
|
558
|
-
}}
|
|
559
|
-
/>
|
|
560
|
-
</div>
|
|
561
|
-
);
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
return (
|
|
565
|
-
<div className="space-y-4">
|
|
566
|
-
<div
|
|
567
|
-
data-provider-toolbar="true"
|
|
568
|
-
className="sticky top-0 z-10 flex min-w-0 flex-wrap items-center justify-start gap-2 rounded-[8px] bg-background/95 px-1 py-1 backdrop-blur sm:justify-end"
|
|
569
|
-
>
|
|
570
|
-
<Button
|
|
571
|
-
variant="outline"
|
|
572
|
-
size="sm"
|
|
573
|
-
onClick={() => handleExport(false)}
|
|
574
|
-
className="gap-1 hover:bg-muted"
|
|
575
|
-
>
|
|
576
|
-
<Download className="size-3" />
|
|
577
|
-
Export
|
|
578
|
-
</Button>
|
|
579
|
-
<Button
|
|
580
|
-
variant="outline"
|
|
581
|
-
size="sm"
|
|
582
|
-
onClick={handleImportClick}
|
|
583
|
-
className="gap-1 hover:bg-muted"
|
|
584
|
-
>
|
|
585
|
-
<Upload className="size-3" />
|
|
586
|
-
Import
|
|
587
|
-
</Button>
|
|
588
|
-
<input
|
|
589
|
-
type="file"
|
|
590
|
-
ref={fileInputRef}
|
|
591
|
-
accept=".json"
|
|
592
|
-
onChange={handleFileChange}
|
|
593
|
-
style={{ display: "none" }}
|
|
594
|
-
/>
|
|
595
|
-
<Button
|
|
596
|
-
variant="outline"
|
|
597
|
-
size="sm"
|
|
598
|
-
onClick={() => setShowImportWizard(true)}
|
|
599
|
-
className="gap-1"
|
|
600
|
-
>
|
|
601
|
-
<Scan className="size-3" />
|
|
602
|
-
Scan
|
|
603
|
-
</Button>
|
|
604
|
-
<Button onClick={() => setShowForm(true)} size="sm" className="gap-1">
|
|
605
|
-
<Plus className="size-4" />
|
|
606
|
-
Add Provider
|
|
607
|
-
</Button>
|
|
608
|
-
</div>
|
|
609
|
-
|
|
610
|
-
{configPath !== null && (
|
|
611
|
-
<div className="flex items-center gap-2 rounded-[8px] bg-muted/15 px-3 py-2 text-xs text-muted-foreground">
|
|
612
|
-
<span className="font-mono truncate" title={configPath}>
|
|
613
|
-
{configPath}
|
|
614
|
-
</span>
|
|
615
|
-
<button
|
|
616
|
-
type="button"
|
|
617
|
-
onClick={() => {
|
|
618
|
-
void copyTextToClipboard(configPath).then((success) => {
|
|
619
|
-
if (!success) return;
|
|
620
|
-
setConfigPathCopied(true);
|
|
621
|
-
setTimeout(() => setConfigPathCopied(false), 2000);
|
|
622
|
-
});
|
|
623
|
-
}}
|
|
624
|
-
className="ml-auto shrink-0 text-muted-foreground transition-colors hover:text-foreground"
|
|
625
|
-
aria-label={configPathCopied ? "Copied config file path" : "Copy config file path"}
|
|
626
|
-
>
|
|
627
|
-
{configPathCopied ? (
|
|
628
|
-
<Check className="size-3 text-status-success" />
|
|
629
|
-
) : (
|
|
630
|
-
<Copy className="size-3" />
|
|
631
|
-
)}
|
|
632
|
-
</button>
|
|
633
|
-
</div>
|
|
634
|
-
)}
|
|
635
|
-
|
|
636
|
-
{error !== null && (
|
|
637
|
-
<div className="border border-border bg-card shadow-sm flex items-center gap-2 rounded-[8px] px-3 py-2 text-sm text-destructive">
|
|
638
|
-
<AlertCircle className="size-4 shrink-0" />
|
|
639
|
-
{error}
|
|
640
|
-
</div>
|
|
641
|
-
)}
|
|
642
|
-
|
|
643
|
-
{providers.length === 0 ? (
|
|
644
|
-
<div className="border border-border bg-card shadow-sm space-y-3 rounded-[8px] py-12 text-center">
|
|
645
|
-
<p className="text-sm text-muted-foreground">No providers configured yet.</p>
|
|
646
|
-
<Button onClick={() => setShowForm(true)} variant="outline" size="sm">
|
|
647
|
-
<Plus className="size-4" />
|
|
648
|
-
Add Your First Provider
|
|
649
|
-
</Button>
|
|
650
|
-
</div>
|
|
651
|
-
) : (
|
|
652
|
-
<div className="space-y-3">
|
|
653
|
-
<div className="inline-flex w-fit gap-1 rounded-[8px] bg-muted/20 p-1">
|
|
654
|
-
{(["all", "personal", "company"] as const).map((tab) => (
|
|
655
|
-
<button
|
|
656
|
-
key={tab}
|
|
657
|
-
type="button"
|
|
658
|
-
onClick={() => setSourceFilter(tab)}
|
|
659
|
-
className={`rounded-md px-3 py-1.5 text-sm font-medium transition-colors ${
|
|
660
|
-
sourceFilter === tab
|
|
661
|
-
? "bg-background text-foreground shadow-sm"
|
|
662
|
-
: "text-muted-foreground hover:text-foreground"
|
|
663
|
-
}`}
|
|
664
|
-
>
|
|
665
|
-
{tab === "all" ? "All" : tab === "personal" ? "Personal" : "Company"}
|
|
666
|
-
</button>
|
|
667
|
-
))}
|
|
668
|
-
</div>
|
|
669
|
-
<div ref={listScrollRef} className="space-y-3">
|
|
670
|
-
{filteredProviders.map((provider) => (
|
|
671
|
-
<ProviderCard
|
|
672
|
-
key={provider.id}
|
|
673
|
-
provider={provider}
|
|
674
|
-
testResults={testResults[provider.id]}
|
|
675
|
-
isTesting={testingProviders.has(provider.id)}
|
|
676
|
-
testingTimeLeft={testingTimeLeft[provider.id]}
|
|
677
|
-
isHighlighted={provider.id === highlightedProviderId}
|
|
678
|
-
onEdit={(p) => setEditingProvider(p)}
|
|
679
|
-
onDelete={handleDeleteProvider}
|
|
680
|
-
onRefreshMetadata={(id) => {
|
|
681
|
-
void refreshProviderMetadata(id);
|
|
682
|
-
}}
|
|
683
|
-
isRefreshingMetadata={refreshingMetadataProviders.has(provider.id)}
|
|
684
|
-
onTest={(id: string) => {
|
|
685
|
-
void runTest(id);
|
|
686
|
-
}}
|
|
687
|
-
/>
|
|
688
|
-
))}
|
|
689
|
-
</div>
|
|
690
|
-
</div>
|
|
691
|
-
)}
|
|
692
|
-
|
|
693
|
-
<ImportWizardDialog
|
|
694
|
-
open={showImportWizard}
|
|
695
|
-
onOpenChange={setShowImportWizard}
|
|
696
|
-
onImportComplete={() => {
|
|
697
|
-
if (onProvidersMutate !== undefined) {
|
|
698
|
-
void onProvidersMutate();
|
|
699
|
-
}
|
|
700
|
-
}}
|
|
701
|
-
/>
|
|
702
|
-
|
|
703
|
-
<ConfirmDialog
|
|
704
|
-
open={confirmOpen}
|
|
705
|
-
onOpenChange={setConfirmOpen}
|
|
706
|
-
title="Delete Provider"
|
|
707
|
-
description="Are you sure you want to delete this provider? This action cannot be undone."
|
|
708
|
-
confirmLabel="Delete"
|
|
709
|
-
variant="destructive"
|
|
710
|
-
onConfirm={executeDelete}
|
|
711
|
-
/>
|
|
712
|
-
</div>
|
|
713
|
-
);
|
|
714
|
-
}
|